CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2005
    Posts
    9

    Binding to TextBox?

    HI there,
    How to bind a cell of a dataSet to TextBox?
    Thanks
    Melvik.

  2. #2
    Join Date
    Sep 2004
    Location
    Tehran(Ir)
    Posts
    469

    Re: Binding to TextBox?

    for a simple binding like a textbox to another textbox,
    Code:
    Binding b=new Binding("Text",textBoxA,"Text");
    textBoxB.DataBindings.Add(b);
    for a complex binding you should give an ICollection as the second parametre with a suitable datamember,for example I bind a dataset to a textbox
    Code:
    string[] strings=new string[]{"number1","number2"};
    Binding b=new Binding("Text",dataSet.Tables[0],"ColumnName");
    textBox.DataBindings.Add(b);
    //for changing the position of datasource(collection)
    //....
    this.BindingContext[dataSet.Tables[0]].Position++;
    or binding an array to a textbox
    Code:
    string[] strings=new string[]{"number1","number2"};
    Binding b=new Binding("Text",strings,null);
    textBox.DataBindings.Add(b);
    //then for changing the position of the datasource(collection)
    this.BindingContext[strings].Position++;
    you should pass the proper parameters to the the dataSource & dataMember otherwise it won't work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured