partham
Active member
Dear Sir/Madam,
We are now using VB.Net 2008.
We have used a DataGridView. The DataSource for the DataGridView is a DataTable.
We have created the DataTable as per the Database table in ORACLE. Suppose, we have the following columns in the DataTable:
A - string
B - string
C - boolean
When the DataGridView appears, it makes columns A and B TextBoxes and C a checkboxcolumn.
However, we want the column B to be a dropdown list.
When we create a DataGridViewComboxCell object and assign the values to display, etc and then try to change the CellTemplate of the DataGridViewColumn (B), it gives a run time error stating that type cast is not possible.
Our request is to kindly let us know how we can use a DataTable as the DataSource of a DataGridView and make one or more of the columns as a ComboBox.
Our code logic is as follows:
' Create the Data Table
' Populate the Data Table fetching data from the Database
' Attach the DataTable as the DataSource of the DataGridView
dgView.DataSource = _dtblModel
' Then create the ComboBox cell
cell = New DataGridViewComboBoxCell
cell.DataSource = getDataFromDB
cell.DisplayMember = "Description"
cell.ValueMember = "Key"
dgView.Column("B").CellTemplate = cell
'<--- Here is an error
We would like to know the correct technique as we are used to DataGrid and not experienced with DataGridView.
Please help us.
Regards,
Partha
We are now using VB.Net 2008.
We have used a DataGridView. The DataSource for the DataGridView is a DataTable.
We have created the DataTable as per the Database table in ORACLE. Suppose, we have the following columns in the DataTable:
A - string
B - string
C - boolean
When the DataGridView appears, it makes columns A and B TextBoxes and C a checkboxcolumn.
However, we want the column B to be a dropdown list.
When we create a DataGridViewComboxCell object and assign the values to display, etc and then try to change the CellTemplate of the DataGridViewColumn (B), it gives a run time error stating that type cast is not possible.
Our request is to kindly let us know how we can use a DataTable as the DataSource of a DataGridView and make one or more of the columns as a ComboBox.
Our code logic is as follows:
' Create the Data Table
' Populate the Data Table fetching data from the Database
' Attach the DataTable as the DataSource of the DataGridView
dgView.DataSource = _dtblModel
' Then create the ComboBox cell
cell = New DataGridViewComboBoxCell
cell.DataSource = getDataFromDB
cell.DisplayMember = "Description"
cell.ValueMember = "Key"
dgView.Column("B").CellTemplate = cell
'<--- Here is an error
We would like to know the correct technique as we are used to DataGrid and not experienced with DataGridView.
Please help us.
Regards,
Partha