2017-10-11 6 views
0

두 열이있는 행을 클릭하면이 5 행의 전체 행이 메시지 상자에 값을 표시하는 방법을 알 수 있습니까?DataGridView에서 C# Windows Forms의 두 번 클릭 기능을 활성화하는 방법

나는 MySQL 데이터베이스를 사용합니다.

 private void allOrders_DoubleClick(object sender, EventArgs e) 
    { 
     this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; 
     this.dataGridView1.MultiSelect = false; 
    } 

질문은 ..

 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) 
    { 
     if (e.RowIndex < 0) 
     { 
      return; 
     } 

     int index = e.RowIndex; 

     dataGridView1.Rows[index].Selected = true; 
    } 

나는이 방법을 만들어 :

나는이 방법이 있나요? MessageBox의 모든 열이있는 행을 표시하려면 어떻게합니까?

+1

mysql과 어떻게 관련이 있습니까? – SeM

+0

또한 다른 모든 이벤트와 마찬가지로 더블 클릭 이벤트를 바인딩 할 수 있습니다. – SeM

+0

나는 이벤트를 두 번 클릭 클릭, 나는이 방법이 있습니다 개인 무효 allOrders_DoubleClick (개체 보낸 사람, EventArgs입니다 전자) { } –

답변

0
private void dataGridView1_DoubleClick(object sender, EventArgs e) 
    { 

    } 

이 작업은 DataGridView 이벤트에 의해 수행됩니다. 위의 코드는 DataGridView에서 두 번 클릭하면 발생합니다.

- 당신은

1 탭을 클릭 이제이 모든 이벤트를 얻을 수있는 이벤트에 대한 속성 창을 클릭에 DataGridView 컨트롤

2의 이벤트의 다양한 얻을 수 있습니다.

해피 ..

0

당신이 DataTable에서 DataGridView의 데이터 소스를 결합 있다고 가정하자 코딩. 예를 들어 는 :

private void InitDataGridView() 
{ 
    DataTable table = new DataTable();   
    table.Columns.Add("1"); 
    table.Columns.Add("2"); 
    table.Columns.Add("3"); 
    table.Columns.Add("4"); 
    table.Columns.Add("5"); 

    table.Rows.Add("1", 2, 3, "4", 5); 
    table.Rows.Add("11", 21, 31, "41", 51); 
    table.Rows.Add("11", 12, 13, "14", 15); 
    table.Rows.Add("21", 22, 23, "24", 25); 
    table.Rows.Add("13", 32, 33, "34", 35); 
} 
dataGridView1.DataSource = table; 

지금 다음 MessageBox 또는 새로운 Form에 전달하거나 원하는 위치를 사용 DoubleClick() 방법은, 예를 들어, 문자열 배열로 선택한 행 집합을 얻을 수 있습니다 볼 수 있습니다 :

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) 
{ 
    DataGridViewRow selectedRow = dataGridView1.Rows[e.RowIndex]; //Get selected Row 
    string[] selectedValues = new string[selectedRow.Cells.Count]; //Init string array or list, or custom object array/list 

    for (int i = 0; i < selectedRow.Cells.Count; i++) 
    { 
     selectedValues[i] = selectedRow.Cells[i].Value.ToString(); //Fill your array with cell values 
    } 

    //Your next code goes here 
} 
관련 문제