GridView에서 특정 Data를 Binding하려면



그리드뷰에 DataBindings -> 고급



DataSource로 변경하고 바인딩할 데이터와 업데이트 모드를 설정한 다음


바인딩 해주면 해당 Data로 바인딩되어 Grdview에 자동적으로 출력한다.




List는 최초 한번만 GridView에 업데이트 되고 ReBinding하여도 

    Update되지 않음

  < 따라서, List => BindingList 를 써야 한다. >

   

'Programming > C#' 카테고리의 다른 글

Input을 전체적으로 Control 하고싶은 경우  (1) 2017.12.26
Virtual, Abstract, Interface  (0) 2017.11.06
Dictionary 탐색중 삭제하기  (0) 2017.08.17
캐스팅 as, is  (0) 2017.06.30
DataGridView 스크롤시 열 고정, 구분자  (0) 2016.12.22
블로그 이미지

SherryBirkin

,

Dictionary<Key, Value> 형태로 쓰게되는데


Key값으로 Loop(반복문)를 돌리고


해당Key만 삭제하면 된다.



foreach(string sKey in Dictionary.Keys.ToList())

{

      // Dictionary.Keys[sKey] == value;  <- Key로 찾은 Value

      Dictionary.Remove(sKey);           <- Key를 이용해서 Value 삭제

}



'Programming > C#' 카테고리의 다른 글

Virtual, Abstract, Interface  (0) 2017.11.06
DataSource Binding 방법  (0) 2017.10.31
캐스팅 as, is  (0) 2017.06.30
DataGridView 스크롤시 열 고정, 구분자  (0) 2016.12.22
Enum에서 정한 Name을 index로 가져오기  (0) 2016.12.22
블로그 이미지

SherryBirkin

,

캐스팅 as, is

Programming/C# 2017. 6. 30. 15:37

개체는 다형성이므로 기본 클래스 형식의 변수는 파생 형식을 가질 수 있습니다. 


파생 형식의 메서드에 액세스하려면 값을 파생 형식으로 다시 캐스팅해야 합니다. 그러나 이러한 경우 단순한 캐스팅을 시도하려면 <xref:System.InvalidCastException>이 throw될 수 있는 위험을 감수해야 합니다. 


이 때문에 C#은 is 및 as 연산자를 제공합니다. 이러한 연산자를 사용하면 예외를 throw시키지 않고 캐스트 성공 여부를 테스트할 수 있습니다. 

일반적으로 캐스트가 성공하면 실제로 캐스트 값을 반환하는 as 연산자가 훨씬 효율적입니다.


 is 연산자는 부울 값만 반환합니다. 따라서 이 연산자는 개체 형식을 결정하고 실제로 캐스트하지는 않는 경우에 사용할 수 있습니다.


as를 사용했을때 int, double, float등에 Null값을 넣을수 없지만

int? a  = 변수면 as int?;

앞뒤로 ?를 붙여주면 변수에 null값이 들어가게 된다.


class SafeCasting { class Animal { public void Eat() { Console.WriteLine("Eating."); } public override string ToString() { return "I am an animal."; } } class Mammal : Animal { } class Giraffe : Mammal { } class SuperNova { } static void Main() { SafeCasting app = new SafeCasting(); // Use the is operator to verify the type. // before performing a cast. Giraffe g = new Giraffe(); app.UseIsOperator(g); // Use the as operator and test for null // before referencing the variable. app.UseAsOperator(g); // Use the as operator to test // an incompatible type. SuperNova sn = new SuperNova(); app.UseAsOperator(sn); // Use the as operator with a value type. // Note the implicit conversion to int? in // the method body. int i = 5; app.UseAsWithNullable(i); double d = 9.78654; app.UseAsWithNullable(d); // Keep the console window open in debug mode. System.Console.WriteLine("Press any key to exit."); System.Console.ReadKey(); } void UseIsOperator(Animal a) { if (a is Mammal) { Mammal m = (Mammal)a; m.Eat(); } } void UseAsOperator(object o) { Mammal m = o as Mammal; if (m != null) { Console.WriteLine(m.ToString()); } else { Console.WriteLine("{0} is not a Mammal", o.GetType().Name); } } void UseAsWithNullable(System.ValueType val) { int? j = val as int?; if (j != null) { Console.WriteLine(j); } else { Console.WriteLine("Could not convert " + val.ToString()); } } }

블로그 이미지

SherryBirkin

,