Reputation: 6177
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
Upvotes: 0
Views: 4237
Reputation: 3120
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());
}
Upvotes: 1