T
Tom
I've made something like that:
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs
e)
{
CurrencyManager cm = (CurrencyManager)
this.BindingContext[((ComboBox)sender).DataSource];
DataRow dr = ((DataRowView) cm.Current).Row;
MessageBox.Show( dr[0].ToString());
}
comboBox1 is binded like this:
DataTable dt = new DataTable("table");
DataColumn ix = new DataColumn("ix",System.Type.GetType("System.String"));
DataColumn iy = new DataColumn("iy",System.Type.GetType("System.String"));
DataRow dr ;
dt.Columns.Add(ix);
dt.Columns.Add(iy);
dr = dt.NewRow();
dr[0] = "asterix";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "abladabla";
dt.Rows.Add(dr);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "ix";
The result is that if I choose abladabla from combobox, the sterix value is
displayed in a messagebox -> The last selected row is returned by the code
in SelectedIndexChanged. Don't know how to make this work "normal". Simply:
I choose asterix -> it displays asterix, I choose abladabla or whatsoever,
it displays it.
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs
e)
{
CurrencyManager cm = (CurrencyManager)
this.BindingContext[((ComboBox)sender).DataSource];
DataRow dr = ((DataRowView) cm.Current).Row;
MessageBox.Show( dr[0].ToString());
}
comboBox1 is binded like this:
DataTable dt = new DataTable("table");
DataColumn ix = new DataColumn("ix",System.Type.GetType("System.String"));
DataColumn iy = new DataColumn("iy",System.Type.GetType("System.String"));
DataRow dr ;
dt.Columns.Add(ix);
dt.Columns.Add(iy);
dr = dt.NewRow();
dr[0] = "asterix";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "abladabla";
dt.Rows.Add(dr);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "ix";
The result is that if I choose abladabla from combobox, the sterix value is
displayed in a messagebox -> The last selected row is returned by the code
in SelectedIndexChanged. Don't know how to make this work "normal". Simply:
I choose asterix -> it displays asterix, I choose abladabla or whatsoever,
it displays it.