change gridview text

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, All,

Anyone knows how to change gridview text info? specifically the gridview
populate from sql db, first column is string rather than number, i want to
change first row in first column into another string, for example "Book" ,
but I don't want this chnage to affect database.

Thanks
 
Hi, All,

Anyone knows how to change gridview text info? specifically the gridview
populate from sql db, first column is string rather than number, i want to
change first row in first column into another string, for example "Book" ,
but I don't want this chnage to affect database.

Thanks


I'm not sure, but I think you are after something like this using the CellFormatting Event:

Private Sub MainGridView_CellFormatting(ByVal sender As Object, ByVal e As _
System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles MainGridView.CellFormatting
With Me.MainGridView.Columns(e.ColumnIndex)
Select Case .Name
Case "Scans"
e.Value = IIf(CType(e.Value, Boolean), "Yes", "No").ToString

Case "Genre"
e.Value = String.Concat(GetGenreName(CType(e.Value, Integer)), ": ", _
Me.MainGrid.Rows(e.RowIndex).Cells("Style").Value)
End Select

End With
End Sub

In the above, in the column named "Scans", the db's Boolean values are displayed as a string value
rather than True or False.

In the column named "Genre", a concacted string is displayed which consists of a string value based
on the db's genre integer value, plus the string value from a hidden column named "Style".


You can also use "e.RowIndex" to target specfic cells.


Gene
 
Back
Top