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

Bounded columns type - MultiComboBoxColumn

1 Answer 83 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kuba
Top achievements
Rank 1
Kuba asked on 26 Nov 2013, 09:57 AM
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

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 29 Nov 2013, 07:51 AM
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 >>
Tags
GridView
Asked by
Kuba
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or