Fixed number of rows in a datagrid

A

Aaron Smith

If I have a datagrid and the bound data file only have 4 rows in it, the
grid will show the 4 rows. However, there is blank space below that
until it reaches the bottom of the grid. Is there a way to have a fixed
number of rows regardless of what data is in the bound table?

Thanks,
Aaron
 
K

Ken Tucker [MVP]

Hi,

To prevent the user from adding a new row set the
dataset.datatables.defaultview.allownew = false.

http://msdn.microsoft.com/library/d...frlrfsystemdatadataviewclassallownewtopic.asp


Ken
---------------------
If I have a datagrid and the bound data file only have 4 rows in it, the
grid will show the 4 rows. However, there is blank space below that
until it reaches the bottom of the grid. Is there a way to have a fixed
number of rows regardless of what data is in the bound table?

Thanks,
Aaron
 
A

Aaron Smith

Actually, I don't want to prevent them from adding a new row. I have a
grid that is about 6 inches long, and with only 3 rows of data more than
half of the grid window is blank with no rows. I want that whole area to
look like the grid. I can't really think of a good way to explain it...
If a grid can have up to 10 lines before scrolling, I want all 10 lines
to be there whether there is data or not...
 
J

james

I don't think you can do that with the datagrid that comes with VB.NET. If I understand you right you want to have a grid drawn
on the screen that has , say 10 rows(with columns) visible, even if there is only 3 of those rows populated with data. Is that
right?
With the regular datagrid, I believe you can only have one extra row visible(that is if you have Allow Edit enabled) and it is
to allow your user to input new data. I think you will have to draw your own datagrid to do what you are wanting to do.
I really don't understand why you would want to do that anyway. That is not common practice with most applications that use a
datagrid to display data and allow editing. Besides, think about this, if you did have it that way, then your user could skip a
row and insert a blank row into the database. Personally, I don't want that to happen.
Well, that's my .02 and it is only my opinion. Good luck on finding a fix to what you are wanting to do.
james
 
A

Aaron Smith

Thanks for the repsonse James. You have the idea of what I want exactly
right. I know this is not standard. The problem is, we are converting
software over to VB.Net that was written in another language. In that
language, they had the grid as I explained. My employer wanted to
recreate that. If there is no way to do it, then so be it, I'm not going
to go through the work of rolling my own datagrid just to have that
happen. The way the other language would work, is you had the grid and
you could not navigate to the other rows if they were blank. You could
only go to the one row following the last row of data, so that you could
enter in a new row.

Thanks again,
Aaron
 
J

james

Your welcome Aaron. The one thing I did think of is, you could append empty rows with null values in each cell at the end of the
actual rows that hold data and then set Edit to the first empty row with the null values. But, I think that would end up
getting pretty messy. You would have to set the display of the grid in such a way that the grid would never show more than 10
rows (empty or not) and if there were any rows without actual data in them, then append as many empty rows as needed to make up
the difference.
Then each time your user added new data to the empty rows, till it filled the 10 row limit, have them scroll and then re-append
more empty rows as needed. See what I mean? It would be a mess keeping track of all that. I would show your boss the new way to
do things and let him see how nice that can be.
james
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top