Home > Net > [WinForm] ComboBox bundle an empty line after the DataTable component, dynamic increase DataRow oper
[WinForm] ComboBox bundle an empty line after the DataTable component, dynamic increase DataRow oper
Time:09-18
The ComboBox components to bind to an already initialized structure but not empty line DataTable on assignment, and then the dynamic increase DataRow, graphic effect is correct, but operation error, The code is as follows,
Private void button1_Click (object sender, EventArgs e) { DtTest=new DataTable (); DtTest. Columns. The Add (" ID "); ComboBox1. DisplayMember="ID"; ComboBox1. ValueMember="ID"; ComboBox1. The DataSource=dtTest; DtTest. Rows. The Add (new Object [] {" 1 "}); }
Run the code
dtTest. Rows. The Add (new Object [] {" 1 "}); Output window after
tip: In the System. For the first time in the ArgumentOutOfRangeException occasional "System. Windows. Forms. DLL" type of exception
One who can help see
CodePudding user response:
Datatable add columns, rows, then the binding combobox DtTest=new DataTable (); DtTest. Columns. The Add (" ID "); DtTest. Rows. The Add (new Object [] {" 1 "}); ComboBox1. DisplayMember="ID"; ComboBox1. ValueMember="ID"; ComboBox1. The DataSource=dtTest;