HighTechTalks DotNet Forums  

DataGridView: Operand in a column

Dotnet Data Tools microsoft.public.dotnet.datatools


Discuss DataGridView: Operand in a column in the Dotnet Data Tools forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Other_Developer_More
 
Posts: n/a

Default 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"
myDataGridView.Columns.Add(myColumn)

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
myDataGridView.CellParsing
Select Case Me. myDataGridView.Columns(e.ColumnIndex).Name
Case "fldRefunds"
'e.value must be something like 25% (and not 2%5), since
'it was already validated in the cellValidating event
'handler
If CStr(e.Value).Contains("%") Then
e.Value = CStr(e.Value).Replace("%", "").Trim
e.Value = CStr(CDbl(e.Value) / 100)
e.ParsingApplied = True
End If
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 +
Parsing).

What am I doing wrong or missing?

Can anybody help me with it?

------------------------

Thanks in advance

Other_Developer_More

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.