Datagridview value translate

  • Thread starter Thread starter George
  • Start date Start date
G

George

Hi everyone. I have the following problem.
I have a datagridview which is binded to a datasource (datatable). I would
like to know how can I translate the values of a column which the data are
numbers (1, 2 and 3) into something more meaningful like a string. For
instance

If the value is 1 I want to make the cell write "Room"
If the value is 2 I want to make the cell write "Suite"

Thanks

George
 
Hi George,

Does this help?
-----------------------CODE STARTS--------------------------
Private Sub DataGridView1_CellFormatting(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) _
Handles DataGridView1.CellFormatting
If e.ColumnIndex = 0 And e.Value <> Nothing Then
Select Case e.Value.ToString
Case "1"
e.Value = "one"

Case "2"
e.Value = "two"

Case "3"
e.Value = "three"

Case Else
e.Value = "unknown"
End Select
End If
End Sub
------------------------CODE ENDS---------------------------

I tried using a better event, but could not find any other event that
captures this.

Some one else might be able to find that event.

Hope this helps!
-Rajneesh
 
Back
Top