DataGrid

N

Nathan Wiegman

Hello,

Does anyone know how to disallow the user from adding rows in the DataGrid?
I don't want to allow the user to add rows to the grid, but at the same time
want the user to be able to edit values in the table. If I set the DataGrid
to ReadOnly, none of the table entries can be modified. If I set one of the
DataColumns to ReadOnly, the user can still add rows in the DataGrid.

Basically, all I am asking for is a table-like grid with a FIXED number of
rows that can be edited by the user.

Thanks,
Nate
(e-mail address removed)
 
K

Kenneth Clive

Well, all you have to do is, in Design view, set the
DataGrid's AllowAddNew property to False. This will
disallow the user to add more rows.

Sincerely,
Kenneth Clive.
 
N

Nathan Wiegman

Thanks Kenneth,

However, when in design view, I fail to see a property named "AllowAddNew"
in the list of properties for my DataGrid...

I am running Microsoft Visual Studio .NET Professional 2003 (Microsoft .NET
Framework v1.1) and have a DataGrid control with its DataSource set to a
DataTable... Any ideas?

Nate
 
J

Jay B. Harlow [MVP - Outlook]

Nathan,
The VB.NET DataGrid itself does not have an AllowNew property.

However the DataView object that the DataGrid ultimately gets bound to does
support an AllowNew property.

When you bind a DataGrid to a Dataset & table name (or to a DataTable) the
DataGrid uses the DataTable.DefaultView property to actually bind to.

Instead of binding to a DataSet & table name I would recommend binding to a
DataView. Associate this DataView with your DataTable from your DataSet,
then set the AllowNew property on this DataView to false. Alternatively you
may be able to change the DataView returned from DataTable.DefaultView, but
remember to change it back when you want to allow adding records...

DataView is in the System.Data namespace along with DataSet & DataTable.

Hope this helps
Jay
 

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