RadButton disable on "start" radGridView Silverligh

5 posts, 1 answers
  1. Rafael
    Rafael avatar
    15 posts
    Member since:
    Jun 2013

    Posted 19 Jun 2013 Link to this post

    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.
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 20 Jun 2013 Link to this post

    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.

  3. Rafael
    Rafael avatar
    15 posts
    Member since:
    Jun 2013

    Posted 20 Jun 2013 Link to this post

    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!
  4. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 21 Jun 2013 Link to this post

    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.

  5. Rafael
    Rafael avatar
    15 posts
    Member since:
    Jun 2013

    Posted 21 Jun 2013 Link to this post

    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);
                
    }

Back to Top