Home All Groups Group Topic Archive Search About
Author
22 Aug 2006 6:04 PM
martin1
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

Author
22 Aug 2006 8:40 PM
gene kelley
On Tue, 22 Aug 2006 11:04:02 -0700, martin1 <mart***@discussions.microsoft.com> wrote:

>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