Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

I found this fix on another forum somewhere (I don't 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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...