728x90
728x90
SMALL

C# 28

[C#] 빈문자열 출력이 가능한 NumericUpDown 컨트롤 만들기

1. 소스public partial class CjNud : UserControl { #region 이벤트 핸들러 /// /// 값이 변경되었을 때 발생하는 이벤트핸들러 /// public event EventHandler ValueChanged; #endregion #region Attributes /// /// 값의 자리수 (숫자의 좌측 빈자리를 0으로 채움, default=2) /// private int m_nDigits = 2; [Browsable(true)] [Category("Data")] [Description("값의 자리수 (숫자의 좌측 빈자리를 0으로 채움)")] publi..

유용한 정보 2025.07.06

[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#] Get MAC address

/// /// 맥주소를 가져오는 함수/// /// 모든 MAC 주소를 구할 것인지의 여부 /// MAC 주소 목록 static public List> GetMacAddress(bool isAll = false) { try { NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces(); if (nics != null && nics.Count() > 0) { List> aMAC = new List>(); /// KeyValuePair foreach (NetworkInterface adapter in nics) { PhysicalAddress addr = adapter.GetPhysicalAddress(); string sAddr = addr..

유용한 정보 2025.04.16

[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#] Excel to PrintPreview

/// /// 엑셀파일을 미리보기한다. /// /// 엑셀파일의 경로 /// 성공하면 에러메세지가 없고 그렇지않으면 발생한 에러 메세지를 반환함 string ExcelToPrintPreview(string sFilePath) { string sErrorMsg = string.Empty; Excel.Application xlApp = null; Excel._Workbook wb = null; Excel.Worksheet ws = null; try { xlApp = new Excel.Application(); //excelApp.ActivePrinter = PrinterSettings.InstalledPrinters[3]; wb = xlApp.Workbooks.Add(sFilePath); if (wb =..

유용한 정보 2025.04.16

[C#] 문자열을 속성으로 갖는 클래스 만들기

1. 소스using System.Reflection; /// /// 문자열을 속성으로 갖는 클래스 /// public class StringValue : System.Attribute { private string _value; /// 문자열 속성값 /// /// 속성값을 설정한다. /// /// 속성값 public StringValue(string value) { _value = value; } /// /// 속성값을 가져온다. /// public string Value { get { return _value; } } } /// /// 자료형 enum에 문자열을 사용할 수 있게 하는 클래스 /// public static class StringEnum { /// /// enum에 Str..

유용한 정보 2025.04.16
728x90
728x90
LIST