Hi all :wave:
how to select checked row of the DataGridView view without loop
Printable View
Hi all :wave:
how to select checked row of the DataGridView view without loop
Hi,Quote:
Originally Posted by shakti5385
Here's an example how to select a row:
Hope it helps,Code:Datagridview1.Rows(index).Selected = True
sparrow1
NO in a DataGridView there is 5 rows. and the 3 rows are checked by me ( there is checkbox column on the DataGridView )
I want to count that three row without using any loop.
Thanks
Any One has Any Idea
Thanks
As I have suggested to you and others many times, if you have data bound to a grid then use the data source, not the grid, to manipulate the data:vb.net Code:
Dim trueRowCount As Integer = CInt(DataTable.Compute("COUNT(ColumnName)", "ColumnName = True"))
If I am not wrong then your code on the datatable not on the DataGridView?
What gave it away?Quote:
Dim trueRowCount As Integer = CInt(DataTable.Compute("COUNT(ColumnName)", "ColumnName = True"))
But I am asking for the DataGridView.
Where does the data in the grid come from? A bound DataTable?
VB.NET Code:
myGrid.DataSource=DataTable
If you DataTable is bound to your DataGridView then the data in each is the same, correct? So then the number of rows in the DataTable with a particular value in a particular column is going to be the same as the number of rows in the DataGridView with that same particular value in the corresponding column. Isn't that the point of data-binding: the data in the control and the source beahve as one?
But when you click on the DataGridView cell then how we can know that the datatable column is also checked?
Well, I can't see why you would want to count the number of rows in a grid containing a certain value if there was still an edit pending, and having a pending edit is the only way that the data in the grid will not be in sync with the data in the DataTable.
Anyway, your question was how to count the rows without a loop. I've shown you how to do that using the bound DataTable. If you want to do it from the grid itself then you can't do it without a loop. You'd just have to check every row and test the value in that column.
Yesterday you was saying to use the Binding source Class so is it necessary to use binding source is the place of datatable?
You do not use a BindingSource in place of a DataTable... anywhere. A BindingSource does not contain any data of its own. A BindingSource is merely an object through which data passes and is viewed to make data-binding easier. When you populate a DataTable you bind it to a BindingSource, then bind the BindingSource to your control(s), e.g. a DataGridView.
I have shown you how to do what you've asked for. If you were supposed to use a BindingSource then my code would have included a BindingSource. It doesn't. Use the DataTable.Compute method, exactly as I have shown.