VB.Net DataGrid/DataView Allow new Problems

jplocster

New member
Joined
Mar 21, 2003
Messages
4
I am using VB.Net and have a very simple form which contains a DataGrid and a few buttons. I want the user to be able to edit the cells in the datagrid but I do not want the user to be able to add new rows by using the "*" row at the bottom of the grid. I would like this "*" row to not exist. I have found the dataview property called AllowNew but no matter how I set this field (true of false) the "*" row always appears and new rows can be added. I must be binding something wrong. I would like some help getting this functionality working correctly Thank you.
Here is the basic outline of my code right now:

Create a Datagrid.
Add the DataGrid control to my form.
Create a DataSet
Create Tables
Add the Tables to the DataSet
Add Columns to the Tables
Bind the DataSet to the DataGrid

then

Dim myDV As DataView
myDV.Table = ds_ClassRoom.Tables(CLASSROOM_TABLE)
myDV.AllowNew = False
myDV.AllowDelete = False
 
you may need to use the DataTable...
Code:
myDV = New DataView(myDT)

myDV.AllowNew = False
myDV.AllowDelete = False
myDV.AllowEdit = True
 
I found this fix on another forum somewhere (I dont understand why I should be required to use the CurrencyManager to do this but it does yield the desired results):

Dim cm As CurrencyManager
Dim dv As DataView
cm = CType(Me.BindingContext(ds_ClassRoom, CLASSROOM_TABLE), CurrencyManager)
dv = CType(cm.List, DataView)
dv.AllowNew = False
dv.AllowDelete = False
dv.AllowEdit = True

Where ds_ClassRoom is a DataSet
and CLASSROOM_TABLE is a string which holds the name of the table I have bound the datagrid to.
Me is the parent form of the DataGrid I think. At least thats what it is on my proggy.

Hope this helps anybody else with the same problem. If anyone knows why the Currency manager has to get involved I would love to hear the explanation. It seems like a hack that was needed because of a feature that was left out.
 
You really dont need the CurrencyMAnager with a Datagrid.
Post all your relevant code and well figure it out.
 
Back
Top