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
close icon

Working with "insert" row in GDBG.

I have a GDBG in which EnableAddNew is enabled. The GDBG is bound to a DataSet that is populated by a DataAdaptor which is filled with the contents of a user-specified table (or view) from a database. I wanted to prevent users from editing those columns which are part of either the primary key for the underlying table or one of the unique indexes for the table or a database view. The following code is used to accomplish this (note that the _dbCmdBuilder class is a homegrown replacement for the CLRs CommandBuilder that corrects some limitations of that class): for (int n = 1; n <= grid.Model.ColCount; n++ ) { if ( _dbCmdBuilder.IsColumnReserved(n - 1) ) { grid[-1,n].CellType = "static"; grid[-1,n].ReadOnly = true; } } This works fine except that it also prevents users from editing those same columns when inserting a new row (in the insertion row at the bottom). How can I keep all the cells in that bottom insertion row editable? Thanks, Andy

6 Replies

AD Administrator Syncfusion Team October 29, 2004 02:11 PM UTC

One way to do this is to handle the grid.Model.QueryCellInfo event, and if e.ColIndex > 0 && e.RowIndex == grid.Model.RowCount, then set e.Style.Enabled = true and e.Style.CellType = "TextBox".


AD Administrator Syncfusion Team October 29, 2004 03:06 PM UTC

Clay, That works, almost. It does allow me to edit the first "key" column. But as soon as you start editing in a cell in the insert row, a new insert row is created which makes the row I''m in revert to non-editable for key columns. This can create a problem if I have a row with multiple key-column cells that need values because after leaving the first key-column, the other cells have reverted to non-editable. I''m considering having a seperate one-row, non-bound grid control above (or below) the GDBG in which users can add new rows... but that seems a bit drastic. Andy >One way to do this is to handle the grid.Model.QueryCellInfo event, and if e.ColIndex > 0 && e.RowIndex == grid.Model.RowCount, then set e.Style.Enabled = true and e.Style.CellType = "TextBox".


AD Administrator Syncfusion Team October 29, 2004 03:12 PM UTC

I had a thought. Somewhere, probably in the ADO.NET stuff, there must be a flag marking new rows as needing to be inserted (via the INSERT statement set-up in the data adapter. If I can figure out which rows in the grid match those rows in the datatable that are "insertable", then I can leave those editable until such time as the dataset is updated via the data-adaptor. I don''t know the CLR or ADO.NET or the grid control''s binding mechanism well enough yet to know where to look for such a flag. Any thoughts? >Clay, > >That works, almost. It does allow me to edit the first "key" column. But as soon as you start editing in a cell in the insert row, a new insert row is created which makes the row I''m in revert to non-editable for key columns. > >This can create a problem if I have a row with multiple key-column cells that need values because after leaving the first key-column, the other cells have reverted to non-editable. > >I''m considering having a seperate one-row, non-bound grid control above (or below) the GDBG in which users can add new rows... but that seems a bit drastic. > >Andy > >>One way to do this is to handle the grid.Model.QueryCellInfo event, and if e.ColIndex > 0 && e.RowIndex == grid.Model.RowCount, then set e.Style.Enabled = true and e.Style.CellType = "TextBox".


AD Administrator Syncfusion Team October 29, 2004 03:21 PM UTC

Try checking if(e.ColIndex > 0 && (e.RowIndex == grid.Model.RowCount || grid.Binder.IsInAddNew)) { // }


MF Mauro Fiore October 31, 2004 02:47 PM UTC

Apologize me but where do I find the GQueryCellInfo event in GridDataBoundGrid object? thanks all, Mauro.


AD Administrator Syncfusion Team October 31, 2004 03:58 PM UTC

It is in the Model member, grid.Model.QueryCellInfo. this.gridDataBoundGrid1.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(Model_QueryCellInfo);

Loader.
Live Chat Icon For mobile
Up arrow icon