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

Problem with separate delete button

4 Answers 90 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Aiden
Top achievements
Rank 1
Aiden asked on 18 Aug 2011, 10:52 PM
I have problem with a Delete button that I added beside this GridView. At the runtime its IsEnabled property goes "false"!
would you please help me to figure it out, why?

Here is the XAML Code:

<telerik:RadGridView Margin="12,12,12,68" Name="radGridView1" AutoGenerateColumns="False" FlowDirection="RightToLeft"
                             ElementExporting="radGridView1_ElementExporting" ShowColumnFooters="True" ShowGroupFooters="True" AutoExpandGroups="True"
                             ShowInsertRow="False" SelectionMode="Extended" ActionOnLostFocus="None">
            <telerik:RadGridView.Columns>
                                                               ...
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

        <Button Height="50" HorizontalAlignment="Left" Margin="68,0,0,12" x:Name="btnDelete" VerticalAlignment="Bottom" Width="50" Click="btnDelete_Click" Command="telerikGrid:RadGridViewCommands.Delete" CommandTarget="{Binding ElementName=RadGridView1}"/>

and this is the code-behind it:

public partial class myProgram : Page
    {
        KDBEntitiesSecond DBContext = new KDBEntitiesSecond();

        public myProgram()
        {            
            InitializeComponent();

            var queryGrid = from c in DBContext.TblLeads select c;
            radGridView1.ItemsSource = queryGrid;

        }
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {            
            DBContext.SaveChanges();
        }
    }

Thanks in advance!

4 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 19 Aug 2011, 08:18 AM
Hello Aiden,

 
The button is disabled, because you have to initialize the command before the InitializeComponent() within MainWindow.xaml.cs:

        public Example()
{
              ICommand deleteCommand = RadGridViewCommands.Delete;
      InitializeComponent();
         }


You may read more about commands in our online documentation, please follow this link.
In addition to this you may also refer to our online demos as well. 


Kind regards,
Vanya Pavlova
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Aiden
Top achievements
Rank 1
answered on 19 Aug 2011, 10:27 PM
Hello Vanya,

I just doing what you noticed about initializing the command, and still doesn't make any difference!
Is there any other reason for this kind of problems?

Regards,
0
Vanya Pavlova
Telerik team
answered on 22 Aug 2011, 07:21 AM
Hi Aiden,


The button uses the built-in Delete command, which removes the SelectedItem/SelectedItems in RadGridView. Since you have intitialized  the command in code-behind and when you select an item (or multiple items) in RadGridView this Button will be enabled.  If the behavior is not the same by your side I would recommend you to send this project to us a new support ticket where we can see what might be wrong.  


Greetings,
Vanya Pavlova
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Kevin
Top achievements
Rank 1
answered on 12 Mar 2012, 07:11 PM
Aiden,

The problem is that you are binding the RadGridView to an IEnumerable (from c in DBContext.TblLeads select c)
To get the built-in Delete, Insert, etc commands to work you must bind to a modifiable collection like List or ObservableCollection.

Readers should ignore Vanya's August 19, 2011 comment since it is not at all accurate.

Kevin Kalitowski
Tags
GridView
Asked by
Aiden
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Aiden
Top achievements
Rank 1
Kevin
Top achievements
Rank 1
Share this question
or