Turn off Datagrid Add Row...

WellsCarrie

Well-known member
Joined
Jul 12, 2005
Messages
95
Location
Arkansas
Programming Experience
5-10
I have an XML file that will hold the FTP settings for a program. The user is allowed to personalize the default settings. I want to just put a copy of the xml file out with the install and allow the user to update it via a special "setting" form inside the application. However I do not want to allow them to have more than one FTP location.

My question is can you allow a datagrid to have editable rows (in this case one only) and disallow the Add Row function? I know how to prevent the add from happening when the update button is pushed but my ideal would be to just prevent the user from even being able to try.

Thanks!
Carrie
 
How are you displaying this data in the grid? Are you placing it in a DataTable and binding that to the grid? if so then you can set the table's DefaultView.AllowNew property to False. The DataView class also has AllowDelete and AllowEdit properties so you can allow the user to insert and delete rows but not edit existing rows if you like. Note that for this to work you must assign the DataTable to the grid's DataSource property. Assigning a DataSet to the DataSource and the table's name to the DisplayMember will just ignore the AllowNew property.
 
Yeah!!! Yes it is one datattable that makes up the data source. I only have this one XML file so I do the following:

VB.NET:
Dim ds as new dataset
Dim dt as new datatable
 
ds.ReadXml("..\XML\ftp.xml")
ds.ReadXmlSchema("..\XML\ftp.xsd")
 
dt = ds.dataTable(0) 'since there is only one
 
dgFTPSettings.DataSource = dt

So if I understand what your saying I can modify it to be this....

VB.NET:
Dim ds as new dataset
Dim dt as new datatable
 
ds.ReadXml("..\XML\ftp.xml")
ds.ReadXmlSchema("..\XML\ftp.xsd")
 
dt = ds.dataTable(0) 'since there is only one
dt.DefaultView.AllowNew = False 
dgFTPSettings.DataSource = dt

That is great!!!! Thanks!
 
Back
Top