728x90
728x90
SMALL

DataGridView 14

[C#] DataGridView에서 콤보박스 컬럼을 사용하기

1. DataGridView에 콤보박스 속성 추가하기 2. DataGridView의 속성 설정하기 3. DataGridView의 이벤트 추가하기 - 외부데이터 구문분석 또는 유효성검사 작업에서 예외를 throw하거나 데이터소스에 데이터를 커밋하려는 시도가 실패했을 발생하는 이벤트이다. 이 이벤트를 추가하지 않으면 각종 이벤트가 발생할 때마다 오류메시지가 표시되고 정상적으로 작동하지않는다. grdData.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(grdData_DataError); private void grdData_DataError(object sender..

유용한 정보 2025.06.24

[C#] DataGridView의 짝수행과 홀수행을 다르게 지정하는 방법

1. 방법DataGridView에서 짝수행과 홀수행의 배경색 및 글자색을 다르게 지정하는 방법은 의외로 간단하다. DataGridView의 속성중에 AlternatingRowsDefaultCellStyle를 설정하면 된다.이값을 설정하지 않으면 아래의 빨강색 사각영역과 같이 기본 형식으로 출력된다. 하지만 이 속성을 설정하면 아래와 같이 출력된다. 2. 예제 소스using CjControls; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System...

유용한 정보 2025.06.03

[C#] DataGridView에서 DataSource 연동하는 방법

1. 칼럼 생성 및 DataDouce와 연동되는 특성 설정하기 DataSource에 연결할 때 사용되는 데이터의 컬럼명을 DataPropertyName에 입력한다. 예를들면 데이터베이스에서 로딩한 데이터를 DataTable로 수신했을 때 그 수신된 데이터그룹의 칼럼명을 DataPropertyName에 입력하면 된다.2. 예제 Random rnd = new Random(); DataTable table = new DataTable(); DataColumn col; col = table.Columns.Add("CHK", typeof(bool)); col.ReadOnly = false; col = table.Columns.Add("NAME"..

유용한 정보 2025.05.24

[C#] 사용자 정의 이벤트 등록 및 사용 예제

1. 이벤트 핸들러 선언 이벤트 핸들러 대리자를 전역으로 선언한다. 가급적이면 이벤트가 실제 발생하는 위치에 선언하는 것이 좋다. 2. 이벤트 등록 이벤트가 발생할 클래스 내부에 위에서 선언한 이벤트 핸들러 대리자로 이벤트 변수를 정의한다. 이벤트 += 이벤트처리함수3. 이벤트 해제이벤트를 해제한 후에는 이벤트가 발생해도 이벤트처리함수가 작동하지 않는다이벤트 -= 이벤트처리함수4. 사용 예제1) 이벤트가 실제 발생하는 곳using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using Syst..

유용한 정보 2025.04.27

[C#] Import Excel File To DataGridView

/// /// Import Excel File To DataGridView /// /// DataGridView Control /// Excel File Path /// if first row in excel is header is then yes else no /// 엑셀파일의 버전이 2003보다 큰지의 여부 /// 성공하면 에러메세지가 없고 그렇지않으면 발생한 에러 메세지를 반환함 string GridViewExcel(Systehttp://m.Windows.Forms.DataGridView grid, string sFilePath, string sSheetName = "Sheet1" , string sFirstRowHeader = "no", bool isExcelFileVersion2003 = f..

유용한 정보 2025.04.16

[C#] DataGridView 에 수직스크롤바가 있는지의 여부 판단하기

1. 소스/// /// 주어진 DataGridView 컨트롤에 수직스크롤바가 있는지의 여부를 구한다. /// /// /// /// - true : 수직스크롤바가 있다. /// - false : 수직스크롤바가 없다. /// bool ExistsVScroll(DataGridView dgv) { try { int height; if (dgv.Rows.Count > 0) height = dgv.Rows[0].Height; else height = dgv.ColumnHeadersHeight; return height * dgv.Rows.Count >= (dgv.Height - dgv.ColumnHeadersHeight); } catch (Exception ex) { KLog.Write(ex.ToStrin..

유용한 정보 2025.04.16

[C#] DataGridView 의 RowHeader 에 일련번호 자동생성하기

/// /// DataGridView 의 RowHeader 에 일련번호 자동생성 /// /// DataGridView 컨트롤 /// 이벤트정보 static void DGV_AutoRowIndex(object sender, DataGridViewRowPostPaintEventArgs e) { DataGridView dgv = sender as DataGridView; try { if (dgv != null && dgv.Rows.Count > 0 && e.RowIndex >= 0) { String rowIdx = (e.RowIndex + 1).ToString(); StringFormat centerFormat = new StringFormat() { Alignment = StringAlignment.Ce..

유용한 정보 2025.04.16
728x90
728x90
LIST