728x90
728x90
SMALL

C# 24

[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

[C#] INI Parser

1. 소스/// /// INI파일의 파서 /// [ComVisible(true)] [ClassInterface(ClassInterfaceType.None)] public class IniParser : IIniParser { private Hashtable KeyPairs = new Hashtable(); private string IniFilePath = ""; /// /// 대소문자 구분을 하는지의 여부 /// private bool ToCase = false; /// /// INI파일을 오픈했는지의 여부 /// public bool IsOpened = false; [StructLayout(LayoutKind.Sequential, Pack = 1)] private class StringPa..

유용한 정보 2025.04.16

[C#] 컨트롤에 들어갈 문자열에서 가장 큰 폭과 높이 구하기

1. 소스/// /// 컨트롤에 들어갈 문자열에서 가장 큰 폭과 높이를 구한다. /// /// 문자열 /// 컨트롤 /// 폭과 높이 static public SizeF GetMaxSize(IEnumerable strings, Control ctrl) { try { float wi = float.MinValue, hi = 0; foreach (string v in strings) { SizeF size = GetStringSize(v, ctrl); hi += size.Height; if (size.Width > wi) wi = size.Width; } return new SizeF(wi, hi); } catch (Exception ex) { KLog.Write(ex.ToString()); } retu..

유용한 정보 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