Bounded columns type - MultiComboBoxColumn

2 posts, 0 answers
  1. Kuba
    Kuba avatar
    13 posts
    Member since:
    Aug 2013

    Posted 26 Nov 2013 Link to this post

    Hello!

    I have RadGridView bounded with DataSet. Is there any way to change type of the columns?

    For example I have DataTable in DataSet with columns: Id, Name and Job. I'm creating data binding between RadGridView
    and DataSet. I would like to have three columns in my RadGridView: Id (typeof DecimalColumn), Name (typeof TextBoxColumn), Job (typeof MultiComboBoxColumn). I know that I have to have Id as System.Int32, Name as System.String in  my DataSet, but how can I change Job into MultiComboBoxColumn?

    Thanks for help, Kuba
  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3945 posts

    Posted 29 Nov 2013 Link to this post

    Hello Kuba,

    Thank you for contacting Telerik Support.

    It is allowed to generate columns of data bound grid manually and specify their type. As to the GridViewMultiComboBoxColumn, it is necessary to set its DataSource property. Here is an example how to configure the described columns and populate the GridViewMultiComboBoxColumn:
    public Form1()
    {
        InitializeComponent();
     
        DataSet dataSet = new DataSet();
     
        DataTable dataTable = new DataTable();
        dataTable.Columns.Add("Id");
        dataTable.Columns.Add("Name");
        dataTable.Columns.Add("Job");
     
        for (int i = 0; i < 10; i++)
        {
            dataTable.Rows.Add(i, "Name" + i, null);
        }
     
        dataSet.Tables.Add(dataTable);
         
        DataTable jobDataTable = new DataTable();
        jobDataTable.Columns.Add("Description");
        for (int i = 0; i < 5; i++)
        {
            jobDataTable.Rows.Add("Job" + i);
        }
        dataSet.Tables.Add(jobDataTable);
     
        radGridView1.AutoGenerateColumns = false;
     
        GridViewDecimalColumn decimalColumn = new GridViewDecimalColumn("Id");
        radGridView1.MasterTemplate.Columns.Add(decimalColumn);
     
        GridViewTextBoxColumn textBoxColumn = new GridViewTextBoxColumn("Name");
        radGridView1.MasterTemplate.Columns.Add(textBoxColumn);
     
        GridViewMultiComboBoxColumn mccbColumn = new GridViewMultiComboBoxColumn("Job");
        mccbColumn.DataSource = dataSet.Tables[1];
     
        this.radGridView1.Columns.Add(mccbColumn);
     
        radGridView1.DataSource = dataSet.Tables[0];
     
        radGridView1.CellBeginEdit += radGridView1_CellBeginEdit;
    }
     
    private void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
    {
        GridViewEditManager editManager = sender as GridViewEditManager;
        if (editManager.GridViewElement.CurrentColumn is GridViewMultiComboBoxColumn)
        {
            RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)this.radGridView1.ActiveEditor;
            editor.EditorControl.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        }
    }

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top