C#
-
[WPF] Datagrid 내에서 항목 삭제하기C# 2024. 5. 28. 11:55
DataGrid 내에 삭제 버튼을 포함하고, 각 행의 항목을 삭제하는 기능을 구현하려면, DataGrid의 각 행에 버튼을 추가하여 해당 버튼을 클릭했을 때 해당 행을 삭제하는 방법을 사용합니다. 이를 위해 DataGridTemplateColumn을 사용하여 각 행에 삭제 버튼을 추가하고, 버튼 클릭 이벤트를 ViewModel의 Command로 바인딩합니다.1. DataGrid에 삭제 버튼 추가먼저 DataGrid의 각 행에 삭제 버튼을 추가하고, 버튼 클릭 이벤트를 Command로 바인딩하는 XAML을 작성합니다.View (XAML) xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http:..
-
문자열 예제C# 2021. 10. 2. 17:35
Substring - 일부분 가져오기 string s3 = "Visual C# Express"; System.Console.WriteLine(s3.Substring(7, 2)); // Output: "C#" String[] pairs = { "Color1=red", "Color2=green", "Color3=blue", "Title=Code Repository" }; foreach (var pair in pairs) { int position = pair.IndexOf("="); if (position
-
Stream 에서 한줄씩 읽기C# 2021. 10. 2. 17:10
int counter = 0; string line; // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader(@"c:\test.txt"); while((line = file.ReadLine()) != null) { System.Console.WriteLine(line); counter++; } file.Close(); System.Console.WriteLine("There were {0} lines.", counter); // Suspend the screen. System.Console.ReadLine();
-
파일 선택. File pickerC# 2021. 10. 2. 02:49
var fileContent = string.Empty; var filePath = string.Empty; using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { //Get the path of specified file fi..
-
파일 읽기, StreamReaderC# 2021. 10. 2. 02:13
인스턴스를 사용하여 StreamReader 파일에서 텍스트를 읽기. using System; using System.IO; class Test { public static void Main() { try { // 인스턴스 생성 // using 을 사용함으로서, 사용후에 close 하게 된다. using (StreamReader sr = new StreamReader("TestFile.txt", Encoding.UTF8)) { string line; // 파일 끝까지 읽어서 출력. while ((line = sr.ReadLine()) != null) { Console.WriteLine(line); } } } catch (Exception e) { // 에러 처리. Console.WriteLine("The ..