DataGridView in 2005

  • Thread starter Thread starter John J. Hughes II
  • Start date Start date
J

John J. Hughes II

How to intercept the data from the row's text box before it's written to the
underlying data source. I need to change the edit data before it stored. I
understand that the CellFormating catches the data before it's displayed but
all the other events seem to occur after the system attempts to write the
data back to the data source. I want to handle writing to the data source
directly.

The DataGridView is bound to a data source which seems to preclude using the
VirtualMode option???

A flow chart of when the events occur for this control would be really
helpful.

Regards,
John
 
"John J. Hughes II" <[email protected]> a écrit dans le message de [email protected]...

| How to intercept the data from the row's text box before it's written to
the
| underlying data source. I need to change the edit data before it stored.
I
| understand that the CellFormating catches the data before it's displayed
but
| all the other events seem to occur after the system attempts to write the
| data back to the data source. I want to handle writing to the data source
| directly.

Try the CellParsing event

Joanna
 
Yep that did it, thanks a lot. I ended up with this to display allow Hex in
the column.

Set manufactureCodeDataGridViewTextBoxColumn Display format to "X" and then
handle the parsing...

private void dataGridView1_CellParsing(object sender,
DataGridViewCellParsingEventArgs e)
{
if (this.dataGridView1.Columns[e.ColumnIndex].Name ==
"manufactureCodeDataGridViewTextBoxColumn")
{
if (e != null && e.Value != null &&
e.DesiredType.Equals(typeof(Int16)))
{
try
{
/// Convert to a hex value
e.Value = Int16.Parse((string)e.Value,
System.Globalization.NumberStyles.AllowHexSpecifier);
e.ParsingApplied = true;
} catch{} ///TODO: Add something intelligent here
}
}
}

Regards,
John
 
John

I have been finding several issues with the datagrid that are actually
caused by the the database project being overwritten every time you
compile. It then looks as if the database isnt updating. If you are
having updating issues chech that the Copy if newer property is set and
NOT the "copy always" property of the database file in the project
explorer. However , if you even open the dbase explorer, the timestamp
will be updated and the database will be overwritten again resulting in
data loss.

Check this posting on MSDN:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=63741&SiteID=1

Greg
 
Back
Top