C# - 데이타 바인딩


아래의 예제는 imap이라는 instance의 Connected / Authenticated / ImapRequest 속성을
TextBox의 text 속성에 binding 하는 예제임

txtIsConnected.DataBindings.Add("TEXT", imap, "Connected");
txtIsAuth.DataBindings.Add("TEXT", imap, "Authenticated");
txtRequest.DataBindings.Add("TEXT", imap, "ImapRequest");

 

광고

2개의 댓글

  1. 궁금한 것이 있어서 여쭙고 싶은 부분이 있습니다.
    컨트롤이 아닌 변수에 DB의 바인딩된 값을 담고 싶을 경우는 어떻게 하는지 알수 있을까요?

    • MDSN을 보면 아래와 같이 DataSet의 값을 Control(textbox)에 binding 하는 예제는 나옵니다.
      text1.DataBindings.Add(new Binding("Text", ds, "customers.custName"));
      text2.DataBindings.Add(new Binding("Text", ds, "customers.custID"));

      헌데.. Binding은 아래의 설명처럼 Control의 Property에 넣는데 사용하는 놈이라서, 변수에 똑같은 방법으로 사용은 안되는듯합니다.
      Use the Binding class to create and maintain a simple binding between the property of a control and either the property of an object, or the property of the current object in a list of objects.

      명쾌한 답변은 아닌듯하네요.. ^^;
      다른 좋은 방법 찾으면 다시 덧글달도록 하겠습니다.

댓글 남기기