달력

82025  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

[c#] DataGridView

c# 2016. 2. 11. 23:31

일을 하다보니 c#을 하게되어 요즘 걸음마 수준으로 c#을 해나가고있다. 간단하게 UI를 구성 할 일이 있어 dataGridView를 사용해 봤는데, 생각보다 좋다. dataGridView에 buttonColumn을 추가하여 사용 하는 방법이다.

이를 응용하면 수정이나 삭제도 가능.

출처 : http://purestarman.tistory.com/m/post/248



private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
    int intchange;
    
    try
    {
        if (dataGridView1.CurrentCell != null)
        {
            // 모든 행의 CheckBox값을 False로 설정
            for (int i = 0; i < dataGridView1.RowCount; i++) 
            {
                dataGridView1[6, i].Value = false; // 6은 CheckBox가 있는 열 번호
            }
            // 현재 선택된 행의 CheckBox값을 True로 설정
            for (int i = 0; i < dataGridView1.SelectedRows.Count; i++) 
            {
                //Convert.ToInt32 => string을 int로 변환
                intchange = Convert.ToInt32(dataGridView1.SelectedRows[i].Cells[0].Value.ToString());
                dataGridView1[6, intchange].Value = true;
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}


'c#' 카테고리의 다른 글

[c#] timer  (0) 2016.03.14
Posted by 초코렛과자
|