This is a migrated thread and some comments may be shown as answers.

RadButton disable on "start" radGridView Silverligh

4 Answers 86 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rafael
Top achievements
Rank 1
Rafael asked on 20 Jun 2013, 01:48 AM
Hi guys,

I am learning Telerik Silverlight Resources and I am using a Telerik radGridView with a radButton in last collumn like examples in official page.
But when I run the application, the radButton appears like disable status and if I click it, its launch the radGridView SelectionChanged row event and so the radButton is active. 

What causes this problem?


XAML Code:
<telerik:RadGridView x:Name="RadGridView1" SelectionChanged="selection_changed">
<telerik:RadGridView.Columns>
<telerik:GridViewColumn Width="90">
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<telerik:RadButton Content="Delete"
  Command="telerikGrid:RadGridViewCommands.Delete"
  CommandParameter="{Binding}" telerik:TouchManager.IsTouchHitTestVisible="False"/>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>
		<telerik:RadGridView.GroupDescriptors>
        <telerik:GroupDescriptor Member="Country"
                                     SortDirection="Ascending" />
    </telerik:RadGridView.GroupDescriptors>
</telerik:RadGridView>

I load grid in code behind:
Code Behind:

protected void LoadRadGridView()
{
radGridView.ItemsSource = _listItems;
	GroupDescriptor descriptor = new GroupDescriptor();
	descriptor.Member = "ItemType";
	descriptor.SortDirection = ListSortDirection.Ascending;
}

Please help me.

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 20 Jun 2013, 07:11 AM
Hi Rafael,

Delete command can be executed only when you have a selected item. Thus it is aware which item to remove from the collection. Do you expect anything different ? Do you want to have a selected item initially ?   

Regards,
Maya
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Rafael
Top achievements
Rank 1
answered on 20 Jun 2013, 01:31 PM
No. I understand the command and I dont want to use this resource. 
I wish that in the radButton's click, it throws my implemented method 
"Delete_Item", where it removes the item from my Item list and so it 
updates the radgridview.

when I click a row, the radbutton gets enabled, 
and the event SelectionChanged from the radGridView is triggered, 

I wish only to use the radButton's click event and somehow get the radButton's line parent.

Any solution to this problem is welcome!
0
Accepted
Maya
Telerik team
answered on 21 Jun 2013, 08:59 AM
Hello Rafael,

Firstly, you can remove the declaration of Command and CommandParameter properties in RadButton's definition and add handler for the Click event. The row in whiche the button is placed can be found through ParentOfType<T>() extension method from the button (which will be the sender in the Click event).

Regards,
Maya
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Rafael
Top achievements
Rank 1
answered on 21 Jun 2013, 05:56 PM
Thanks Maia!

Your sugestion help me!

XAML Code:

<telerik:RadGridView x:Name="radGridViewItems" 
                              ShowGroupPanel="False"
                              AllowDrop="False"
      CanUserFreezeColumns="False"
RowIndicatorVisibility="Collapsed"
AutoExpandGroups="True"
AutoGenerateColumns="False"
ColumnWidth="*" Width="870" MinWidth="870"  Height="244" Margin="12,6,12,0" SelectionChanged="radGridViewItems_SelectionChanged" >
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Header="Item Selecionado" HeaderTextAlignment="Center" IsFilterable="False"
   DataMemberBinding="{Binding Name}" />
                    <telerik:GridViewDataColumn Header="Detalhamento" HeaderTextAlignment="Center" IsFilterable="False"
   DataMemberBinding="{Binding Details}" />

                    <telerik:GridViewColumn Width="85" >
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadButton x:Name="btnDelete" Content="Delete" Click="btnDelete_Click"/>
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
                    </telerik:GridViewColumn>
               </telerik:RadGridView.Columns>

               <telerik:RadGridView.GroupDescriptors>
                    <telerik:GroupDescriptor Member="TypeOrder"  SortDirection="Ascending"></telerik:GroupDescriptor>
                </telerik:RadGridView.GroupDescriptors>
 </telerik:RadGridView>

Code Behind:

private void radGridViewIItems_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
 {
            try
            {
                 /*Open editor window data from radgrid*/
            }
            catch (Exception erro)
            {
                Message.ErrorMessage(erro.Message);
            }
        }

 private void btnDelete_Click(object sender, RoutedEventArgs e)
 {
            var senderElement = e.OriginalSource as FrameworkElement;
            var row = senderElement.ParentOfType<GridViewRow>();

            if (row != null)
            {
/* prevent  selectionchanged event to be triggered */
                radGridViewIItems.SelectionChanged -= radGridViewItensSelecionados_SelectionChanged;
                row.IsSelected = true; 
                radGridViewItems.SelectionChanged += radGridViewItensSelecionados_SelectionChanged;
            }
   /*method that delete item from Item list*/
            this.Delete();
            
   }

/*method that load radGridViewItems considering Grouping by Item
public void loadRadGridViewItems()
{
            radGridViewItems.ItemsSource = null;
            radGridViewItems.ItemsSource = this._listaItems.Where(c => c.AlterarItem.Equals(false)).ToList();
            GroupDescriptor descriptor = new GroupDescriptor();
            descriptor.Member = "TypeOrder";
            descriptor.SortDirection = ListSortDirection.Ascending;
            this.radGridViewItems.GroupDescriptors.Add(descriptor);
            
}

Tags
GridView
Asked by
Rafael
Top achievements
Rank 1
Answers by
Maya
Telerik team
Rafael
Top achievements
Rank 1
Share this question
or