DataGridView: Operand in a column - 03-06-2006 , 08:01 AM
Suppose I have a DataGridView (VS 2005) (called myDataGridView) which is
bound to a MS Access DataBase, one of the columns is a percentage, it’s
defined as a ‘double’ field in the Access side, as to the DataGridView side,
the column was created using the folowing formatting (I skipped column
naming, data binding and other irrelevant formattings):
Dim myColumn As new DataGridViewColumn
myColumn.DefaultCellStyle.Format = "P"
The column is displayed just fine, all the cells are displayed as ’25 %’,
with an underlying data value of ‘0,25’.
I want to give the user the possibility of having a percentage operator, so
the user types percentages as ’25 %’, and they are converted to 0,25 when
parsing the cell in the CellParsing event handler.
So, I wrote the CellParsing event handler like:
Private Sub myDataGridView_CellParsing(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellParsingEventA rgs) Handles
Select Case Me. myDataGridView.Columns(e.ColumnIndex).Name
'e.value must be something like 25% (and not 2%5), since
'it was already validated in the cellValidating event
If CStr(e.Value).Contains("%") Then
e.Value = CStr(e.Value).Replace("%", "").Trim
e.Value = CStr(CDbl(e.Value) / 100)
e.ParsingApplied = True
End Select 'Select Case Me.DataGridView1...
End Sub 'myDataGridView_CellParsing
According to my understanding, it should work, but it doesn’t. It produces a
dataError event with a context of 768: DataGridViewDataErrorContexts(Commit +
What am I doing wrong or missing?
Can anybody help me with it?
Thanks in advance
|Thread Tools||Search this Thread|