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

RadGridView - GridViewComboBoxColumn datasource lost

3 Answers 163 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alejandro
Top achievements
Rank 1
Alejandro asked on 26 Oct 2012, 06:24 PM
Hi... i'm having a problem when i set a datasource to a cell with one GridViewComboBoxColumn... when i set the datasource = null or with 0 elements... all the rows that have the GridViewComboBoxColumn clear the datasource... 

i'm using a code like this

((Telerik.WinControls.UI.GridViewComboBoxColumn)(cell.RowInfo.Cells["NameCell"].ColumnInfo)).DataSource = listElements;

listElements is a List<Object> that have 0 items... and clear all the cells in all the rows

Cheers!

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 31 Oct 2012, 12:37 PM
Hi Alejandro,

Thank you for writing.

The issue in this case is the the column does not contains all possible values in its data source. Even though you change the data source of the editors, the column itself should contain all possible values that you might assign to the editors. 

Here is an example. In your grid you want to have the combo editor of the first row to display values "1-5" and the combo editor on the second row "6-10". To have this scenario working, the data source of the column should contains all possible values "1-10".

Please give this approach a try and let me know how it works for you.
 
Greetings,
Stefan
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Nadia Sangiovanni
Top achievements
Rank 1
answered on 08 Jan 2013, 09:09 PM
Hi Support,

I would like to perform the scenario described earlier. The combo editor of the first row to display values "1-5" and the combo editor on the second row "6-10".
Can you give an example on how to perform this scenario?

Regards,
Nadia
0
Stefan
Telerik team
answered on 10 Jan 2013, 10:12 AM
Hello Nadia,

Here is a small sample demonstrating this:
public Form1()
{
    InitializeComponent();
 
    DataTable mainTable = new DataTable();
    mainTable.Columns.Add("Number");
 
    for (int i = 1; i <= 10; i++)
    {
        mainTable.Rows.Add(i);
    }
 
    GridViewComboBoxColumn col = new GridViewComboBoxColumn();
    col.FieldName = "Number";
    radGridView1.Columns.Add(col);
    col.Width = 200;
 
    radGridView1.CellEditorInitialized += radGridView1_CellEditorInitialized;
     
    radGridView1.Rows.Add(7);
    radGridView1.Rows.Add(3);
    radGridView1.Rows.Add(8);
    radGridView1.Rows.Add(1);
}
 
void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
 
    if (editor != null)
    {
        RadDropDownListEditorElement element = (RadDropDownListEditorElement)editor.EditorElement;
         
        if (e.Row.IsOdd)
        {
            element.DataSource = new string[] { "1", "2", "3", "4", "5" };
        }
        else
        {
            element.DataSource = new string[] { "6", "7", "8", "9", "10" };
        }
 
        element.SelectedIndex = element.FindString(e.Value.ToString());
    }
}

Another example is available here: http://www.telerik.com/support/kb/winforms/gridview/cascading-comboboxes-in-radgridview.aspx.

I hope this helps.
 
Kind regards,
Stefan
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Tags
GridView
Asked by
Alejandro
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Nadia Sangiovanni
Top achievements
Rank 1
Share this question
or