简体   繁体   中英

How to get a Telerik Multi column combo box value which is a column in rad grid view?

I want to get the first element of telerik multi combo box which is a column of a telerik grid view

when user selects a row i want to get the first element of that row and pass it to my DB

i've done some thing but i geuss it's not enough

    if (Ref_MultiColumnComboBox.MultiColumnComboBoxElement.SelectedIndex >= 0)
        {
            var tr = Ref_MultiColumnComboBox.MultiColumnComboBoxElement
                .EditorControl.Rows[Ref_MultiColumnComboBox.MultiColumnComboBoxElement.SelectedIndex]
                    .Cells["Id"].Value.ToString();
            MessageBox.Show("m= {0}" + "  //    " + tr);
        }
        else
        {
            MessageBox.Show("", "Error");
        }

the problem is that when user selects some row or doesn't selectedindex is allways -1

Here is one way to do it for RadMultiColumnComboBox control:

void radMultiColumnComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    GridViewDataRowInfo selectedRow = (GridViewDataRowInfo)radMultiColumnComboBox1.SelectedItem;
    Console.WriteLine(selectedRow.Cells["Id"].Value.ToString());
}

The SelectedItem provides a reference to the selected row in the inner grid, from where you can access its cells and values.

If GridViewMultiComboBoxColumn is used, then you can use either the ValueChanged event, or the CellValueChangned events to get the row of the currently selected item:

void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
{
    RadMultiColumnComboBoxElement mccbEditor = (RadMultiColumnComboBoxElement)e.ActiveEditor;
    GridViewDataRowInfo selectedRow = (GridViewDataRowInfo)mccbEditor.SelectedItem;
    Console.WriteLine(selectedRow.Cells["Id"].Value.ToString());
}

void radGridView1_ValueChanged(object sender, EventArgs e)
{
    RadMultiColumnComboBoxElement mccbEditor = (RadMultiColumnComboBoxElement)radGridView1.ActiveEditor;
    GridViewDataRowInfo selectedRow = (GridViewDataRowInfo)mccbEditor.SelectedItem;
    Console.WriteLine(selectedRow.Cells["Id"].Value.ToString());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM