To reproduce, run the code.
Observed:
System.Argument OutOfRangeExcep tion was unhandled
Message="Invali dArgument=Value of '0' is not valid for
'SelectedIndex' .\r\nParameter name: SelectedIndex"
t2.c1 contains legal value.
Why this error occurs ?
How to fix ?
Andrus.
using System.Windows. Forms;
using System.Data;
using System;
class testForm : Form {
testForm() {
DataTable t = new DataTable();
t.Columns.Add(" displaymember") ;
t.Columns.Add(" valuemember");
t.Rows.Add("low er", "l");
ComboBox comboBox1 = new ComboBox();
comboBox1.Displ ayMember = "displaymember" ;
comboBox1.Value Member = "valuemembe r";
comboBox1.DataS ource = t;
comboBox1.AutoC ompleteSource = AutoCompleteSou rce.ListItems;
comboBox1.AutoC ompleteMode = AutoCompleteMod e.SuggestAppend ;
DataTable t2 = new DataTable();
t2.Columns.Add( "c1");
t2.Rows.Add("l" );
comboBox1.DataB indings.Add("Se lectedValue", t2, "c1");
Controls.AddRan ge(new Control[] { comboBox1 });
}
[STAThread]
static void Main() {
Application.Run (new testForm());
}
}
Observed:
System.Argument OutOfRangeExcep tion was unhandled
Message="Invali dArgument=Value of '0' is not valid for
'SelectedIndex' .\r\nParameter name: SelectedIndex"
t2.c1 contains legal value.
Why this error occurs ?
How to fix ?
Andrus.
using System.Windows. Forms;
using System.Data;
using System;
class testForm : Form {
testForm() {
DataTable t = new DataTable();
t.Columns.Add(" displaymember") ;
t.Columns.Add(" valuemember");
t.Rows.Add("low er", "l");
ComboBox comboBox1 = new ComboBox();
comboBox1.Displ ayMember = "displaymember" ;
comboBox1.Value Member = "valuemembe r";
comboBox1.DataS ource = t;
comboBox1.AutoC ompleteSource = AutoCompleteSou rce.ListItems;
comboBox1.AutoC ompleteMode = AutoCompleteMod e.SuggestAppend ;
DataTable t2 = new DataTable();
t2.Columns.Add( "c1");
t2.Rows.Add("l" );
comboBox1.DataB indings.Add("Se lectedValue", t2, "c1");
Controls.AddRan ge(new Control[] { comboBox1 });
}
[STAThread]
static void Main() {
Application.Run (new testForm());
}
}
Comment