【问题标题】:Set first column of table as link将表格的第一列设置为链接
【发布时间】:2013-04-26 13:53:42
【问题描述】:

我正在从 mysql 加载我的表,我想创建第一列链接。我的意思是链接到另一个表格。我想显示学生详细信息,当单击名称程序将打开一个新表单并显示有关学生的所有信息。有人知道该怎么做吗?

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();

【问题讨论】:

    标签: c# mysql datagridview


    【解决方案1】:

    您可以在以下事件下处理:

    dataGridView1_CellClick
    

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

    示例代码:

    if (this.dataGridView1.CurrentCell != null) 
    {
        string valueofcell=dataGridView1.CurrentCell.Value.ToString();
        // Raise the corresponding form as per you required
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 2020-03-06
      • 2022-06-27
      • 2023-02-07
      • 1970-01-01
      相关资源
      最近更新 更多