2013-12-14 45 views
0

如何獲得單擊的單元格的值並將其轉移到第二種形式上?獲取單元格的值並將其轉移到第二種形式

這是我到目前爲止的代碼:

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) 
    { 
     if (e.ColumnIndex == 1) 
     { 
      var form2 = new Form2(); 
      this.Hide(); 
      form2.Show(); 
     } 
    } 

回答

1

變化形式的構造函數,將獲得價值,如:

public Form2(String passCellValue) 
    { 
     InitializeComponent(); 
    } 

然後調用這樣的:

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) 
{ 
    if (e.ColumnIndex == 1) 
    { 
     String cellValue; 
     cellValue = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString(); 
     var form2 = new Form2(cellValue); 
     this.Hide(); 
     form2.Show(); 
    } 
} 
0

它很容易

private void gridAgentDetails_Click(object sender, EventArgs e) { for (int i = 0; i < this.gridAgentDetails.CurrentRowIndex; i++) {  string str = gridAgentDetails.Text; }} 

plaese檢查鏈接

How to get column value of grid in C# Windows application?

和傳輸數據,可以使一般財產或可變。請檢查這個鏈接。

http://social.msdn.microsoft.com/Forums/vstudio/en-US/08943b7b-9603-49ad-950c-62e8f8325df2/how-to-pass-value-data-grid-view-click-to-another-form?forum=vbgeneral

相關問題