Datagridview value translate

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top