I am binding a radgridview to a datatable the datatable contains a field ‘TankLevel’ that can have one of 5 values ‘1/4’, ‘half’, ¾’ , ‘Full’ or ‘Unknown’ I want to display this column as a GridViewComboBoxColumn and display the value from the underlying datatable and have each of the 5 values available in the comboboxcolumn dropdown. When I bind to the datatable the combobox is populated with the data but combobox in each row has every row available in the dropdown! How can I make each row show the underlying record but irestrict the dropdown to the 5 values n order that the user can select from the other 4 values.
Dim cboCol As GridViewComboBoxColumn = New GridViewComboBoxColumn
cboCol.Name = "cboCol"
cboCol.HeaderText = "Fill Level"
cboCol.DataSource = sVehDT
cboCol.ValueMember = "TankLevel"
cboCol.DisplayMember = "TankLevel"
cboCol.FieldName = "TankLevel"
Me.RadGridView1.Columns.Add(cboCol)
6 Answers, 1 is accepted
The code would look something like this:
Me
.RadGridView1.AutoGenerateColumns =
False
Me
.RadGridView1.DataSource = sVehDT
Dim
cboCol
As
GridViewComboBoxColumn =
New
GridViewComboBoxColumn
Dim
lstTankLevel
As
List(Of
String
) =
New
List(Of
String
)(
New
String
() _
{
"1/4"
,
"half"
,
"3/4"
,
"Full"
,
"Unknown"
})
cboCol.Name =
"cboCol"
cboCol.HeaderText =
"Fill Level"
cboCol.DataSource = lstTankLevel
cboCol.ValueMember =
"TankLevel"
cboCol.DisplayMember =
"TankLevel"
cboCol.FieldName =
"TankLevel"
Me
.RadGridView1.Columns.Add(cboCol)
' Then some code to add the rest of the columns
Thanks for your reply to my post. I have implemented your suggestion and am now adding the columns at runtime all columns are populated with the data from the dtatatable apart from the "TankLevel' combobox which is blank but has the values available in the dropdown.
regards
Joe
I'm a little confused by your reply. Is your problem solved? If so, please mark my reply as the solution. If not, please elaborate on the issue.
Thanks,
Robert
Found the issue, I changed the bound items to an indexed list and the combobox behaved as I wanted it to. Thanks for your help with this issue.
Joe
You can insert the column or move it after it is added to the grid:
radGridView1.Columns.Insert(1, comboColumn);
//or
radGridView1.Columns.Move(5, 0);
I hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Progress Telerik