Итак, у меня есть набор данных, который вытаскивает определенные ячейки из файла excel и заполняет столбец datagridview. Однако ячейки, которые я вытягиваю, действительно должны быть заголовками, а не нормальными столбцами в datagridview. Итак, есть ли простой способ превратить этот столбец данных в текст заголовка? Чтобы помочь ellaborate, я предоставил код ниже, включая комментарии.Я ищу способ сделать свой первый столбец в своем datagridview заголовке
' The following lines specify the exact cells I with to pull from the excel file and populates the first column of the datagridview
MyCommand1 = New OleDbDataAdapter("Select * from [myWorksheet$A15:B21]", MyConnection)
'Here is my dataset'
ds1 = New System.Data.DataSet()
DataGridView1.DataSource = ds1.Tables(0).DefaultView
'So at this point I have a datagridview with a column of data from the exact cells
' from the excel file that I want
'This last part is code I found on MSDN which will hide the column headers and will turn the first column into headertext. Essentially it is adding an additional column to the left and turning that into headertext.
Private Sub DataGridView8_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles DataGridView8.CellPainting
Dim rowNumber As Integer = 1
For Each row As DataGridViewRow In DataGridView8.Rows
If row.IsNewRow Then Continue For
row.HeaderCell.Value = "Row " & rowNumber
rowNumber = rowNumber + 1
Next
DataGridView8.AutoResizeRowHeadersWidth(_
DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders)
End Sub
'If anyone can find out a way for me to make the first column headertext it would make my day.
Как переключатель col1 как заголовок и col2 в первом ряду? – matzone
Да, это именно то, что я хочу сделать. – stackexchange12
Я не уверен, но я думаю, что для этого потребуется два шага. Переместить столбец в строку в таблице. Затем отобразите его. – matzone