Limiting rows in a datagid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do you show only the top n rows of a datable in a datagrid without
actually removing the rows from the datatable. Is there the equivalent of
the SQL TOP command for filtering the rows?

Thanks,

Oldman
 
You can combine a TOP X statement with an ORDER BY statement in SQL. You
can also filter your data if it is in a DataView. Set the RowFilter property
to a string that looks like a SQL WHERE clause, but without the WHERE
keyword. You may also want to look into data paging, for which there are
many samples. E.g., using the built-in data paging of the DataGrid (look up
"paging, DataGrid control" in Visual Studio help)
 
Thanks durstin but I'm working with a datatable that is used for other
purposes and all the rows in the Datatable need to be there so limiting the
rows that get filled into the datatable from SQL is not an option.
The RowFilter property seems to be my problem. There isn't a WHERE clause
that you can generate that will give you the top n rows.
The built-in data paging only applies to the Web control version of the
DataGrid. I don't see the equivalent in the Windows.Forms.Datagrid. Am I
missing something?

Thanks,

Chris
 
Back
Top