헤더와 셀 값을 가운데로 정렬해보자


1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
 
            // 헤더 값을 가운데로 정렬
            dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;            
            
            // 셀 값을 가운데로 정렬
            dataGridView1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
 
            // 0번째 컬럼값 전체 가운데로 정렬
            dataGridView1.Columns[0].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
 
            // Column1의 전체 셀값 가운데로 정렬
            dataGridView1.Columns["Column1"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
 
cs


'Winform' 카테고리의 다른 글

winform 현제 셀값 가져오기(위치포함)  (0) 2019.01.30
winform 열 숨기기  (0) 2019.01.30
winform 각 행의 색표시  (0) 2019.01.30
winform 차트 예제  (0) 2019.01.30
winform 엑셀 저장(초고속)  (0) 2019.01.29

윈폼 사용할때 보면 데이터그리드뷰가 밋밋할 때가 있다 보기도 좋지않고...


그럴때 각 행마다 색을 다르게 하면 좀더 이쁘고 가독성도 좋다


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
//짝수 홀수 열 색지정
// rows 대신 column을 쓰면 각 column 색이 바꿔집니다 ㅎㅎ
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
       if (i % 2 != 0)
         {
             dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.FromArgb(240255240);
         }
         else
         {
              dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.FromArgb(240255255);
         }
     }

//짝수 홀수 열 색지정(한줄)

dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Aqua;

cs


'Winform' 카테고리의 다른 글

winform 열 숨기기  (0) 2019.01.30
winform 헤더, 셀 값 가운데로 정렬  (0) 2019.01.30
winform 차트 예제  (0) 2019.01.30
winform 엑셀 저장(초고속)  (0) 2019.01.29
winform 엑셀 죽이기 완벽한 방법  (0) 2019.01.29

윈폼에 있는 차트 예제를 정리해 보았다


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
32
33
                    //차트 해보자 테스트
 
                    //차트 시리즈1 삭제(초기화)
                    chart1.Series.Clear();
 
                    //시리즈 추가
                    //(각각을 시리즈라하고 Series[0], Series[1]로 표시할 수도 있다
                    chart1.Series.Add("LG");
                    chart1.Series.Add("SPEC");
 
                    //legend 위치
                    //LG, SPEC 두개 시리즈를 합쳐서 하나의 Legends라고 한다 마찬가지로 [0]번지 표시 가능
                    chart1.Legends[0].Alignment = StringAlignment.Center;
                    chart1.Legends[0].Docking = Docking.Bottom;
                    chart2.Legends[0].Alignment = StringAlignment.Center;
                    chart2.Legends[0].Docking = Docking.Bottom;
 
                    //색지정, 스타일 지정
                    // 원래 디폴트 값은 막대이지만 선이나 점선을 하고 싶을때에는 아래와 같이..
                    chart1.Series["SPEC"].ChartType = SeriesChartType.Line;
                    chart1.Series["SPEC"].Color = Color.Red;
                    chart1.Series["SPEC"].BorderWidth = 3;
                    chart1.Series["SPEC"].BorderDashStyle = ChartDashStyle.Dash;
 
                    //포인츠 초기화
                    chart1.Series["LG"].Points.Clear();
 
                    // 값 넣기
                    // LG 시리즈에 1, 100막대를 넣음 AddY()만 써도 
                    chart1.Series["LG"].Points.AddXY(1,100);
 
 
 
cs


'Winform' 카테고리의 다른 글

winform 헤더, 셀 값 가운데로 정렬  (0) 2019.01.30
winform 각 행의 색표시  (0) 2019.01.30
winform 엑셀 저장(초고속)  (0) 2019.01.29
winform 엑셀 죽이기 완벽한 방법  (0) 2019.01.29
winform DataGridView to Excel  (0) 2019.01.22

+ Recent posts