简体   繁体   中英

Change the column header caption in a WinForm DataGridView

How to change the row name with option button?

If option button export selected:

Private sub optexport_click()
    txtimport = "I"
    fgcargo.textmatrix(0,2) = "bl number"
    fgcargo.textmatrix(0,4) = "date"
 end sub

If option button import selected:

Private sub optimport_click()
    txtimport = "E"
    fgcargo.textmatrix(0,2) = "so number"
    fgcargo.textmatrix(0,4) = "date"
 end sub

The GridView will take it's column names from the data source. This means that if you have a column named "bl_number" in the database, the column in the GridView will name the column "bl_number".

You could try something like the following:

fcargo.HeaderRow.Cells(2).Text = "bl number"
fcargo.HeaderRow.Cells(4).Text = "date"

Where Cells(ByVal index As Integer) is the index of the column in the GridView (0 based).

Hope this helps.

NOTE: This will not work with a Windows Forms DataGridView control.
For a Windows Forms DataGridView, go into it's columns collection. You can change the header text for each column there. In code, you could try the following:

fcargo.Columns(2).Name = "bl number"
fcargo.Columns(4).Name = "date"

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM