0

I am loading my table from mysql and I want to make first column link. I mean link to another form. I want to display student details and when click on a name program will open a new form and display all info about student. Anyone have any idea about how to do?

DataTable table = new DataTable();
MySqlDataAdapter adapsql = new MySqlDataAdapter("SELECT  name, surname, dob, sex, nationality, mobile, notes FROM student", connection);
adapsql.Fill(table);
dataGridView1.DataSource = table;
int x = (dataGridView1.RowCount)-1;
label21.Text = Convert.ToString(x);

cmd = connection.CreateCommand();
cmd.CommandText = @"SELECT * FROM reservation";

MySqlDataReader Reader = cmd.ExecuteReader();

if (!Reader.HasRows) return;
while (Reader.Read())
{
    reservation.Add(Convert.ToInt16(GetDBString("roomID", Reader)));

}
Reader.Close();
4

1 回答 1

0

您可以在以下事件下处理此问题:

dataGridView1_CellClick

获取 datagridiview 的 CurrentCell 值并使用此信息打开您的第二个表单并将所需信息添加到您在那里的字段中。

示例代码:

if (this.dataGridView1.CurrentCell != null) 
{
    string valueofcell=dataGridView1.CurrentCell.Value.ToString();
    // Raise the corresponding form as per you required
} 
于 2013-04-26T14:14:09.670 回答