Check out the Format and Parse events on the cells. In the following
example, the data is stored as 75000 but the user wants the data displayed
as "75k" instead. This converts it from 75000 to 75k for display, and
converts it back when going the other way. You should be able to do this to
parse the dates.
CellFormatting happens between the data source and the screen.
CellParsing happens between the screen and the data source.
myGrid.CelFormatting += OnCellFormatting;
myGrid.CellParsing += OnCellParsing;
private sub OnCellFormatting(sender object,
DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == myGrid.Columns("columnIcareAbout"))
{
//setting this to true signals the grid that this
// column is being dynamically updated. If you don't
// do this, you will get an infinite loop if you have
// also set the column to have its size automatically
// determined.
e.FormattingApplied = true;
//get the row being populated; format this cell
if (e.Value == "75000")
e.Value = "75K";
}
}
private sub OnCellParsing(sender object, DataGridViewCellParsingEventArgs e)
{
if (e.ColumnIndex == myGrid.Columns("columnIcareAbout"))
{
//get the row being populated; format this cell
if (e.Value == "75K")
e.Value = "75000";
}
}
RobinS.
GoldMail.com
"TheSteph" <Th******@NoSpam.comwrote in message
news:e$*************@TK2MSFTNGP05.phx.gbl...
Hi !
I have a DataGridView with a Date (DateTime) Column.
When a user edit the cell and change the date I woulk like to allow him to
write "081501" and programmatically transform the entered date to
"2008/15/01"( using a custom method called TransformDate(string
ARawDate))
But I can't find any DataGridView event to call the TransformDate method
and replace the user input by the computed value. I always get a
"DataError".
Does anybody if this kind of transformation is possible in a DataGridView
and Where is the best place to put the call to the transformation method ?
Thanks for your help !
Steph.