Search the cell value (Cell.Value) in the ComboBox.Items property collection to get the index of the value selected in the combo box cell.
Using Code
This example creates a combo box cell and searches for the selected item.
[VB]
Imports GrapeCity.Win.MultiRow
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim comboBoxCell1 As New ComboBoxCell
comboBoxCell1.Name = "comboBoxCell1"
comboBoxCell1.Items.Add("Tokyo")
comboBoxCell1.Items.Add("Nagoya")
comboBoxCell1.Items.Add("Osaka")
GcMultiRow1.Template = Template.CreateGridTemplate(New Cell() {comboBoxCell1})
GcMultiRow1.SetValue(0, "comboBoxCell1", "Nagoya")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim gcMultiRow As GcMultiRow = Me.GcMultiRow1
If TypeOf gcMultiRow.CurrentCell Is ComboBoxCell Then
Dim comboBoxCell As ComboBoxCell = TryCast(gcMultiRow.CurrentCell, ComboBoxCell)
Dim selectedValue As Object = comboBoxCell.Value
Dim selectedIndex As Integer = -1
If Not selectedValue = Nothing Then
selectedIndex = comboBoxCell.Items.IndexOf(selectedValue)
End If
MessageBox.Show(String.Format("Selected Index: {0}", selectedIndex))
Else
MessageBox.Show("Present cell is not ComboBoxCell.")
End If
End Sub
|
[CS]
using GrapeCity.Win.MultiRow;
private void Form1_Load(object sender, EventArgs e)
{
ComboBoxCell comboBoxCell1 = new ComboBoxCell();
comboBoxCell1.Name = "comboBoxCell1";
comboBoxCell1.Items.Add("Tokyo");
comboBoxCell1.Items.Add("Nagoya");
comboBoxCell1.Items.Add("Osaka");
gcMultiRow1.Template = Template.CreateGridTemplate(new Cell[] { comboBoxCell1 });
gcMultiRow1.SetValue(0, "comboBoxCell1", "Nagoya");
}
private void button1_Click(object sender, EventArgs e)
{
GcMultiRow gcMultiRow = this.gcMultiRow1;
if (gcMultiRow.CurrentCell is ComboBoxCell)
{
ComboBoxCell comboBoxCell = gcMultiRow.CurrentCell as ComboBoxCell;
object selectedValue = comboBoxCell.Value;
int selectedIndex = -1;
if (selectedValue != null)
{
selectedIndex = comboBoxCell.Items.IndexOf(selectedValue);
}
MessageBox.Show(string.Format("Selected Index: {0}", selectedIndex));
}
else
{
MessageBox.Show("Present cell is not ComboBoxCell.");
}
}
|
See Also