我使用计时器刷新datagridview。请帮助我每 10 秒刷新一次 datagridview 。我找不到代码在刷新或排序 datagridview 后所选单元格将保持不变请帮助我..
private void timer1_Tick(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
SqlCommand cmd = new SqlCommand("SELECT (Cust_No) as [Customer ID],(Cust_surname) as [Surname], (Cust_fname) as [First Name], (Cust_mi) as [Middle Initial], (Cust_address) as [Address], (Cust_ContactNO) as [Contact Number], (Cust_Faxno) as [Fax Number], (Cust_Tin)as [TIN] FROM Customer WHERE cust_status like ('Active')");
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
da = new SqlDataAdapter(cmd);
ds = new DataSet("ds");
da.Fill(ds);
ds.Tables[0].TableName = "table_mirror";
dataGridView2.DataSource = ds.Tables["table_mirror"];
}
else
{
SqlCommand cmd1 = new SqlCommand("SELECT (comp_no) as [Company ID],(comp_name) as [Company Name], (comp_contactperson) as [Contact Person], (comp_address) as [Address], (comp_contactno) as [Contact No], (comp_fax) as [Fax], (comp_Tin) as [Tin] FROM Company WHERE comp_status like ('Active')");
cmd1.CommandType = CommandType.Text;
cmd1.Connection = conn;
da = new SqlDataAdapter(cmd1);
ds = new DataSet("ds");
da.Fill(ds);
ds.Tables[0].TableName = "table_mirror";
dataGridView2.DataSource = ds.Tables["table_mirror"];
}
}