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

GridDataBoundGrid - Losing Cell value in new record

Hi,

I have a GDBG where all cells are static except the one in AddNewRecord. This is achieved by using PrepareViewStyleInfo and having following code in handler:

private void _dataGrid_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
GridDataBoundGrid gdbg = sender as GridDataBoundGrid;
if (e.RowIndex > gdbg.Model.Rows.HeaderCount)
{
if(e.ColIndex <= 0)
return;
if( gdbg[e.RowIndex, e.ColIndex] == null)
return;
// Make sure we are in Term column
int termColIndex = gdbg.Binder.NameToColIndex("Term");
if(e.ColIndex == termColIndex)
{
if(gdbg.EnableAddNew && e.RowIndex == gdbg.Model.RowCount)
{
e.Style.CellType = "TextBox";
e.Style.ReadOnly = false;
}
else
{
e.Style.CellType = "Static";
e.Style.ReadOnly = true;
}
}
}
}

When I type info into the cell, if I hesitate between typing keys (for a couple of seconds) the value of the cell is lost. I then need to click on the new AddNewRecord for the record with the lost cell value to disappear and begin entering values again.

It seems strange that this only happens if there is some time between typing keys. (The focus on the cell doesn't seem to be lost while this occurs.)

The only other event I handle is CurrentCellAcceptedChanges, which does not get called.

Has anyone seen this type of behaviour before and know a workaround?

Thanks in advance.





3 Replies

AD Administrator Syncfusion Team October 27, 2006 01:03 PM UTC

If I change the code in PrepareViewStyleInto to set the appropriate column to TextBox then thhis doesn't occur...

However, I want all the cells in the grid to be Static except the AddNewRowRecord in this column, which should be TextBox so that the user can enter in values.

The code that I use to do this is:

if(gdbg.EnableAddNew && e.RowIndex == gdbg.Model.RowCount)
{
e.Style.CellType = "TextBox";
e.Style.ReadOnly = false;
}
else
{
e.Style.CellType = "Static";
e.Style.ReadOnly = true;
}

Is there a better way to achieve the same result without the value getting wiped when hesitations occur between typing in text?


AD Administrator Syncfusion Team October 27, 2006 01:22 PM UTC

Hi Vito,

To set the celltype of the AddnewRecord, you need to handle the Model.QueryCellInfo event. Here is a code snippet

//Form load..
this.gridDataBoundGrid1.Model.QueryCellInfo +=new GridQueryCellInfoEventHandler(Model_QueryCellInfo);

private void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if( e.ColIndex > 0 && e.RowIndex > 0 )
{
GridModel model = sender as GridModel;
if(e.RowIndex == model.RowCount )
e.Style.CellType = "TextBox";
else if( e.RowIndex == model.RowCount - 1 && gridDataBoundGrid1.Binder.IsAddNew)
e.Style.CellType = "TextBox";
else
e.Style.CellType = "Static";
}
}

Best Regards,
Haneef


AD Administrator Syncfusion Team October 27, 2006 02:04 PM UTC

Thanks, that worked

Loader.
Live Chat Icon For mobile
Up arrow icon