We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How do I cancel editing of one colum under certain conditions?

Hi, I have a boundgrid with a datatable as the source. I wish to catch edits on one of the colums (the editable primary key) and block the change if records exist in child tables. The strange this is, in the following code, the gridboundcolumns collection is always returning zero records? Any suggestions? Thanks in advance, Damien Sawyer Private Sub gdItems_CurrentCellChanging(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles gdItems.CurrentCellChanging Dim i As Int16 = gdItems.GridBoundColumns.IndexOf(Me.gdItems.Binder.InternalColumns("ItemID")) If gdItems.CurrentCell.ColIndex = i Then MsgBox("Can''t Edit this cell") e.Cancel = True End If End Sub

4 Replies

AD Administrator Syncfusion Team March 31, 2005 01:23 AM UTC

In a hierarchical GriddataBoundGrid, when you call grid.Binder.AddRelation to set up the hierarchies, the call returns a GridHierarchyLevel object. This object has a property, GridBoundColumns, and it is this collection that holds the GridBoundColumns used in the hierarchical GridDataBoundGrid.


DS Damien Sawyer March 31, 2005 01:37 AM UTC

Thanks Clay, But I didn''t set up this grid as heirarchial... It''s just ''normal''... '' Bind the DataGrids to their datatables Me.gdItems.DataSource = p_dsItems.Tables("dtItems") thanks in advance, DS


AD Administrator Syncfusion Team March 31, 2005 08:11 AM UTC

The grid.GridBoundColumnsCollection is only populated if you have explicitly added GridBoundColumns. If you have not added GridBoundColumns, then you always use the grid.Binder.InternalColumns collection, which should not be empty after its datasource has been set. Instead of
Dim i As Int16 = gdItems.GridBoundColumns.IndexOf(Me.gdItems.Binder.InternalColumns("ItemID"))
If gdItems.CurrentCell.ColIndex = i Then
    MsgBox("Can''''t Edit this cell")
    e.Cancel = True
End If
try
Dim i As Int16 = gdItems.Binder.NameToColIndex("ItemID")
If gdItems.CurrentCell.ColIndex = i Then
   MsgBox("Can''''t Edit this cell")
   e.Cancel = True
End If
Another options is to just set gdItems.Binder.InternalColumns("ItemID").StyleInfo.ReadOnly = True in Form.Load. If you never want a cell in the column to become teh currentcell, you can also set ").StyleInfo.Enabled = False. Or, you could set ").StyleInfo.CellType = "Static". This way you could do things by setting a property instead of handling an event.


DS Damien Sawyer March 31, 2005 11:05 PM UTC

Fantastic Clay, Thanks for your help! :-) DS

Loader.
Live Chat Icon For mobile
Up arrow icon