我已经为我的datagridview创建了一个线程来提高性能 但我仍然可以看到我项目的滞后和反应迟钝。我想要的就是顺利运行。 还有一个问题,如果我的datagridview中有大量数据,我是否应该创建一个加载内容来欺骗用户?
注意看我的代码,我做对了吗?或者我应该做些更好的事情?
public studentManager()
{
InitializeComponent();
ThreadStart thread1Start = new ThreadStart(LoadGrid);
Thread t1 = new Thread(thread1Start);
t1.Start();
}
public void LoadGrid()
{
if (radGridView1.InvokeRequired)
radGridView1.Invoke(new Action(() =>
{
//For Buttons stuffs
add.Image = Properties.Resources.adde;
add.Enabled = true;
delete.Image = Properties.Resources.deleted;
delete.Enabled = false;
update.Image = Properties.Resources.updated;
update.Enabled = false;
errorProvider1.Clear();
//Datagridview
MySqlConnection connection = new MySqlConnection(MyConnectionString);
connection.Open();
try
{
MySqlCommand cmd = connection.CreateCommand();
cmd.CommandText = "Select * from studenttable";
MySqlDataAdapter adap = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
adap.Fill(ds);
radGridView1.DataSource = ds.Tables[0].DefaultView;
label8.Text = "Student Information loading completed!";
radGridView1.Columns[0].HeaderText = "Student Number";
radGridView1.Columns[0].Width = 100;
radGridView1.Columns[1].HeaderText = "Name";
radGridView1.Columns[1].Width = 300;
radGridView1.Columns[2].HeaderText = "Section";
radGridView1.Columns[2].Width = 50;
radGridView1.Columns[3].HeaderText = "Email";
radGridView1.Columns[3].Width = 100;
radGridView1.Columns[4].HeaderText = "Course";
radGridView1.Columns[4].Width = 50;
radGridView1.Columns[5].HeaderText = "Gender";
radGridView1.Columns[5].Width = 150;
radGridView1.Columns[6].IsVisible = false;
}
catch (Exception)
{
throw;
}
finally
{
if (connection.State == ConnectionState.Open)
{
connection.Clone();
}
}
}));
else
{
label8.Text = "Data information is loading........";
}
}
如果我的问题出现问题,请通知我,因为我在stackoverflow中是新手。谢谢:D