Prevent "Allow Add" in a data table

I'd like for the user to have the ability to make changes to the datagrid, just not allow add/delete rows in the datatable. (not exactly read only) My apologies for not explaining myself that well.

I can work around this so that the newly add/deleted valules aren't applied to the database, but seems somewhat like a sloppy method.

I should likely reconsider having separate add/delete forms for this particular section of my application.

However, if anyone knows of a way or has a suggestion on how I may accomplish what I'm trying to do with a datatable I'd really like to hear it :D
 
You can allways declare the datarow 'WithEvents' and grab the 'RowChanging' event of it... there you can:
Visual Basic:
    Private Sub dt_RowChanging(ByVal sender As Object, ByVal e As System.Data.DataRowChangeEventArgs) Handles dt.RowChanging
        If e.Action = DataRowAction.Add Then
            'Validate whatever you want...
        End If
    End Sub

Alex :p
 
As he's using some 3rd party column styles dor the datagrid they (the columns) must be somehow confused with the header names... who know what kind of code is behind those "custom columns"??

Wouldn't it be sheaper to buy a whole new grid component?
Even if not I think it would allways be better, the diference can't be so big...

www.devexpress.com ... XtraGrid component... rulezzzz

Alex :p
 
Last edited:
Yeah, it's really wierd that these column styles would prevent me from using a dataview =/

Thanks for the tip on the datagrid Alex. I'll check it out.

I was looking at one from syncfusion, but it was rather pricey for the amount I'll be using it.
 
I'm sorry about the link error... :(
I use almost all DevExpress .net controls and they're all great and on top of this, the support repplyes to in 24hours max...

Alex :P
 
Robby said:
JABE, the problem is that he said the datgrid doesn't take kindly to Dataviews, I'm not really sure why though. :(

Oh, I guess I was thrown off by his initial question:

I was curious if anyone knew of a way to make a data table prevent adding/deleting records using a dataview??

Anyway, if the datagrid is bound to a datatable instead, it's just a matter of getting to the DefaultView of the datatable:

CType(theDataGrid.DataSource, DataTable).DefaultView.AllowDelete = False
CType(theDataGrid.DataSource, DataTable).DefaultView.AllowNew = False
 
JABE said:
Oh, I guess I was thrown off by his initial question:



Anyway, if the datagrid is bound to a datatable instead, it's just a matter of getting to the DefaultView of the datatable:

CType(theDataGrid.DataSource, DataTable).DefaultView.AllowDelete = False
CType(theDataGrid.DataSource, DataTable).DefaultView.AllowNew = False

LOL Aye. that would do it. I'm sorry about Jabe.

Thanks for the reply. I'll try that out. May save me some money... and then I can buy that other grid control after I pay my income tax! :D
 
Back
Top