how to Count the filled rows in the DataGrid
Hi,
Please can some one help me to know "How many rows are the datagrid filled with?"
Thanks a lot
Hi,
Please can some one help me to know "How many rows are the datagrid filled with?"
Thanks a lot
Use the .rowcount property of the datagrid
or
the .count property of the datasource of the datagrid
dim cm as currencymanager = ctype(me.bindingcontext(datagrid1.datasource),currencymanager)
dim intRowCount as integer = cm.count
Thanks to your reply
but there is no "Rowcount" property for the datagrid
and also there is no "Count" property for the DataSource
PS. I'm using vb.net 2003
thanks again
Dear Ken Tucker,
Thanks for your reply
I tried it but it gives me only 1 row count in all cases
I have around 400 rows
Is there some more code I must write it ?!!
Thank U too much
I get 77 with this example.
Dim conn As SqlConnection
Dim strConn As String
Dim da As SqlDataAdapter
Dim ds As New DataSet
strConn = "Server = .; Database = NorthWind; Integrated Security = SSPI;"
conn = New SqlConnection(strConn)
da = New SqlDataAdapter("Select * From Products", conn)
da.Fill(ds, "Products")
DataGrid1.DataSource = ds.Tables("Products")
Dim cm As CurrencyManager
cm = CType(Me.BindingContext(DataGrid1.DataSource), CurrencyManager)
Dim intRows As Integer = cm.Count
Me.Text = String.Format("Number of rows {0}", intRows)
dim int rows as integer = ds.tables("Products").rows.count
save having to get a new CM.
Thanks every body
this code is working now
Dim
MyRows As Integer = MyDataGrid.DataSource.tables("MyTable").rows.count
public
static int dataTableRowCount(DataTable dt){
int dtRowCount = 0;
foreach(DataRow myRow in dt.Rows)
if (myRow.RowState != DataRowState.Deleted)
dtRowCount ++;
return dtRowCount;
}