i use grid 3.6.When i use begininvoke to bind the gridcontrol,I often meet a exception which show
“Index (zero based) must be greater than or equal to zero and less than the size of the argument list”
But if I use a general DataGridView to show my data,there will be none exception.If I just
use UI thread to get data and bind the gridcontrol,there will be none exception too.
my code:
delegate void MyDeletegate();
string connString = “server=.;uid=sa;pwd=speed;database=Northwind”;
private void button5_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(ThreadBind));
t.Name = “NewThread”;
t.Start();
}
private void ThreadBind()
{
this.BeginInvoke(new MyDeletegate(BindGrid));
}
private void BindGrid()
{
SqlConnection sqlconn = new SqlConnection(connString);
sqlconn.Open();
SqlDataAdapter adp = new SqlDataAdapter(“SELECT * FROM Products”, sqlconn);
SqlCommandBuilder sqlcomm = new SqlCommandBuilder(adp);
DataSet ds = new DataSet();
adp.Fill(ds);
BindingSource bs = new BindingSource();
bs.datasource=ds;
bs.datamember=ds.Table[0].TableName;
this.dataGridView1.DataSource = bs;
sqlconn.Close();
}
Can you tell me what’s the reason?How can I get the large data in another thread and bind the gridcontrol?
thanks!
Imported from legacy forums. Posted by handsomesun (had 2037 views)