fixed 10 row Datagridview

larris

Member
Joined
Mar 13, 2006
Messages
23
Programming Experience
1-3
hi to all!!

I have a datagridview which is populated from a database based on a user imput on a textbox.what i want is to have a fixed 10 row datagrid.I populate the datagrid in the form load event handler with 10 blank rows.the code is this :
Datagridview1.Rows.Add(10).
but when the query result from the database is less than 10 rows (say 5 rows) the datagrid shows only the 5 rows and a black screen bellow row 5.
how can i populate the rest 5 row with blank rows so the user wont se a blank screen?
 
If you set the datasource, the rows you first added is removed and new ones added based on the datasource. If there is only 5 rows in datasource, then that is what is displayed, no more, no less. If you want to display a datasource, it will display the datasource. If you're not happy with the datasource, then you have to change the datasource. Ok, sorry for the sarcasm, but I think you got the point.

So for the solution to a 10 rows fixed datagridview, add your 10 empty rows and write in the values to each item that you read from the real datasource.
 
Can you add the necessary rows based on the number of rows from the Database?

Datagridview1.Rows.Add(10 - COUNT)

Where COUNT is the number of records returned?
Not sure how it works exactly, but shouldn't it add blank rows to the end of the Grid?
 
"Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."
 
Back
Top