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.
Unfortunately, activation email could not send to your email. Please try again.

GridDataBoundGrid - Losing Cell value in new record

Thread ID:

Created:

Updated:

Platform:

Replies:

51048 Oct 26,2006 10:21 AM Oct 27,2006 10:04 AM Windows Forms 3
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On October 26, 2006 10:21 AM

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.





Administrator [Syncfusion]
Replied On October 27, 2006 09:03 AM

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?

Administrator [Syncfusion]
Replied On October 27, 2006 09:22 AM

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

Administrator [Syncfusion]
Replied On October 27, 2006 10:04 AM

Thanks, that worked

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;