Grid Combobox Column

7 posts, 1 answers
  1. Joe Bohen
    Joe Bohen avatar
    71 posts
    Member since:
    May 2009

    Posted 08 Jul 2011 Link to this post

    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)

  2. Answer
    Robert
    Robert avatar
    9 posts
    Member since:
    Apr 2011

    Posted 08 Jul 2011 Link to this post

    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
  3. Joe Bohen
    Joe Bohen avatar
    71 posts
    Member since:
    May 2009

    Posted 09 Jul 2011 Link to this post

    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
  4. Robert
    Robert avatar
    9 posts
    Member since:
    Apr 2011

    Posted 09 Jul 2011 Link to this post

    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
  5. Joe Bohen
    Joe Bohen avatar
    71 posts
    Member since:
    May 2009

    Posted 11 Jul 2011 Link to this post

    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
  6. Bao
    Bao avatar
    54 posts
    Member since:
    Jan 2015

    Posted 12 Sep 2017 in reply to Robert Link to this post

    Normally it will add the column in the last index, how can i change position for combobox column ?
  7. Dimitar
    Admin
    Dimitar avatar
    2831 posts

    Posted 13 Sep 2017 Link to this post

    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.
Back to Top