Please how to find the index of the named column ( ColeName ) in DataGridView1 ..
I have a single and unique column that I put it to generate the days in months
I tried like this but in have bad result because in want to have index of column not rows
If Conne.State = 1 Then Conne.Close()
Conne.Open()
Dim Cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand("SELECT Factory1 , Factory2 , Factory3 , Factory4 , Factory5 From Table_Factory", Conne)
Dim rdr As SqlClient.SqlDataReader = Cmd.ExecuteReader()
rdr.Read()
If rdr.HasRows Then
DT.Rows(1)(ColeName) = rdr.Item(3).ToString
DT.Rows(2)(ColeName) = rdr.Item(4).ToString
DT.Rows(3)(ColeName) = rdr.Item(5).ToString
DT.Rows(4)(ColeName) = rdr.Item(6).ToString
DT.Rows(5)(ColeName) = rdr.Item(7).ToString
End If
Cmd = Nothing
rdr.Close()
Conne.Close()

Mada BlackPosted Jan 12, 2023, 9:29 AM
Thank you Naimish
But i have only one column named ( ColeName ) filled by same columns of daysin month
Naimish MakwanaPosted Jan 12, 2023, 9:19 AM
Please refer below link.
https://www.codeproject.com/Questions/363284/how-to-get-the-index-of-DataGridView-from-its-name
https://social.msdn.microsoft.com/Forums/en-US/d227f08a-dc5f-4bdc-9c58-5117e6e1bd97/how-to-find-column-index-through-column-name-in-gridview?forum=aspwebformsdata