谁说不行啊?我试了很好使,给你个简单点的代码:
private void Form1_Load(object sender, System.EventArgs e)
{
SqlConnection con=new SqlConnection("database=Test;data source=(local);user id=sa;password=sa");
SqlCommand cmd=new SqlCommand();
cmd.Connection=con;
cmd.CommandText="select UserID,UserPwd from Users";
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand=cmd;
DataTable dt=new DataTable();
da.Fill(dt);
this.dtgData.DataSource=dt;
}
private void dtgData_Click(object sender, System.EventArgs e)
{
dtgData.Select(dtgData.CurrentRowIndex);
}
private void dtgData_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
dtgData_Click(sender,e);
}