我想获得 telerik多组合框的第一个元素,它是telerik网格视图的一列
当用户选择一行时,我想获取该行的第一个元素并将其传递给我的数据库
我已经完成了一些事情,但我认为这还不够
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");
}
问题在于,当用户选择某行或不selectedindex
时,总是-1
答案 0 :(得分:1)
以下是 RadMultiColumnComboBox 控制的一种方法:
void radMultiColumnComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewDataRowInfo selectedRow = (GridViewDataRowInfo)radMultiColumnComboBox1.SelectedItem;
Console.WriteLine(selectedRow.Cells["Id"].Value.ToString());
}
SelectedItem提供对内部网格中所选行的引用,您可以从中访问其单元格和值。
如果使用 GridViewMultiComboBoxColumn ,则可以使用ValueChanged事件或CellValueChangned事件来获取当前所选项目的行:
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());
}