2013-04-26 36 views
0

我正在從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(); 

回答

0

您可以在下面的事件在處理這個問題:

dataGridView1_CellClick 

獲取datagridiview的CurrentCell值,並利用這些信息來打開你的第二個表格和所需的信息添加到你那裏的領域。

示例代碼:

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

謝謝!這工作真棒:) – QueenOfError 2013-04-26 14:48:37

相關問題