This is a migrated thread and some comments may be shown as answers.

Grid Combobox Column

6 Answers 240 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joe Bohen
Top achievements
Rank 1
Joe Bohen asked on 08 Jul 2011, 03:32 PM

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

Sort by
0
Accepted
Robert
Top achievements
Rank 1
answered on 08 Jul 2011, 08:08 PM
You should be binding your datatable to the RadGridView, not the GridViewComboBoxColumn.  The DataSource property of the GridViewComboBoxColumn is for the dropdown list.

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
0
Joe Bohen
Top achievements
Rank 1
answered on 09 Jul 2011, 11:44 AM
Hi Robert

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
0
Robert
Top achievements
Rank 1
answered on 09 Jul 2011, 05:36 PM
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
0
Joe Bohen
Top achievements
Rank 1
answered on 11 Jul 2011, 11:59 AM
Hi 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
0
Bao
Top achievements
Rank 1
answered on 13 Sep 2017, 03:57 AM
Normally it will add the column in the last index, how can i change position for combobox column ?
0
Dimitar
Telerik team
answered on 13 Sep 2017, 05:21 AM
Hello Bao,

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Joe Bohen
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Joe Bohen
Top achievements
Rank 1
Bao
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or