We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Knowing if a row has been selected in a DataGrid.

Hi, I have a DataGrid (Windows Forms), which I have programmed such that whole rows are selected. When a user presses a button, I want to check whether an item in the DataGrid has been selected. Is there a DataGrid property that indicates whether a row has been selected in the DataGrid. For example, in C++ (MFC) the list view control has a property that has a value of -1 when no row has been selected in the control. If a row is selected, it returns the row number. Is there something similar for the DataGrid? I noticed that the method CurrentRowIndex returns the currently selected row or the last selected row when nothing is highlighted in the DataGrid. If there isn't something equivalent, what would be the best way of figuring it out, without having to iterate through the entire DataGrid? Thanks.

2 Replies

TH Thomas November 6, 2002 07:29 AM

Don't worry about this one...I figured it out. > Hi, > > I have a DataGrid (Windows Forms), which I have programmed such that whole rows are selected. When a user presses a button, I want to check whether an item in the DataGrid has been selected. > > Is there a DataGrid property that indicates whether a row has been selected in the DataGrid. > For example, in C++ (MFC) the list view control has a property that has a value of -1 when no row has been selected in the control. If a row is selected, it returns the row number. > Is there something similar for the DataGrid? > I noticed that the method CurrentRowIndex returns the currently selected row or the last selected row when nothing is highlighted in the DataGrid. > > If there isn't something equivalent, what would be the best way of figuring it out, without having to iterate through the entire DataGrid? > Thanks.


JI Jim March 18, 2003 06:02 AM

So, what was your solution? I'd be really interested to know. Thanks, Jim

Loader.
Live Chat Icon For mobile
Up arrow icon