J
jp2msft
I use unbound DataGridView controls in my form (simply because I have to
manually message my data before populating the DataGridView with it).
Say I clear all the info from the DataGridView:
DataGridView1.Columns.Clear()
Now I manually add new columns to fill:
DataGridView1.Columns.Add("Date_Time", "Date_Time")
DataGridView1.Columns.Add("Station_ID", "Station_ID")
DataGridView1.Columns.Add("Operator", "Operator")
Now try to fill these columns using their Column Names used above:
Dim dgRow As New DataGridViewRow()
dgRow.CreateCells(DataGridView1)
dgRow.Cells["Date_Time"].Value = DateTime.Now().ToString()
dgRow.Cells["Station_ID"].Value = "Test Station 1"
dgRow.Cells["Operator"].Value = Form1.EmployeeNameTextBox.Text
DataGridView1.Rows.Add(dgRow);
Here is the error:
ArgumentException was unhandled
Column named Date_Time cannot be found.
Parameter name: columnName
Is there a fix for this?
Microsoft has overloaded this method to accept an integer Index or a string
columnName, but the columnName version does not appear to work. My
DataGridColumns are added Programmatically, so I don't always know what the
Index value of the DataGridColumns are going to be.
Is there a way to get the DataGridColumn's Index using the columnName? Is
this the way to get around this problem?
I have also coded a different version using CellTemplates, but it threw the
same error.
manually message my data before populating the DataGridView with it).
Say I clear all the info from the DataGridView:
DataGridView1.Columns.Clear()
Now I manually add new columns to fill:
DataGridView1.Columns.Add("Date_Time", "Date_Time")
DataGridView1.Columns.Add("Station_ID", "Station_ID")
DataGridView1.Columns.Add("Operator", "Operator")
Now try to fill these columns using their Column Names used above:
Dim dgRow As New DataGridViewRow()
dgRow.CreateCells(DataGridView1)
dgRow.Cells["Date_Time"].Value = DateTime.Now().ToString()
dgRow.Cells["Station_ID"].Value = "Test Station 1"
dgRow.Cells["Operator"].Value = Form1.EmployeeNameTextBox.Text
DataGridView1.Rows.Add(dgRow);
Here is the error:
ArgumentException was unhandled
Column named Date_Time cannot be found.
Parameter name: columnName
Is there a fix for this?
Microsoft has overloaded this method to accept an integer Index or a string
columnName, but the columnName version does not appear to work. My
DataGridColumns are added Programmatically, so I don't always know what the
Index value of the DataGridColumns are going to be.
Is there a way to get the DataGridColumn's Index using the columnName? Is
this the way to get around this problem?
I have also coded a different version using CellTemplates, but it threw the
same error.