DataBinding the UI control to the array element ? RRS feed

  • 問題

  • Hi ~

    For the databinding for the control class

    i.e. Control.DataBindings.Add(string propertyName,object dataSource,string dataMember)

    for the parameter of dataSource and dataMember, how can i bind the value of the control to the specific in array

    e.g. if i have a class

    public class Person{
    public object[] extras


    then i want to bind the control with the second element in Person.extras i.e. Person.extras[1]

    i try the following ways, but not success

    controlObj.DataBindings.Add("Text, person.extras, new object[] {1});


    controlObj.DataBindings.Add("Text", person, "extras[1]");

    The Control i need to being binding to is allow to bind the single value only, such as TextBox, can just bind to a sigle value. But ListBox can bind to a list or array because it allow multiple to display in the control


    2007年1月25日 上午 08:11



  • HI,

    Please reference the following article:


    2007年1月26日 上午 01:13
  • Thank tihs ~

    But what i want to do is to bind the textbox to the "single element" inside the array. From the example stated in 1st post, Person class have an attribute "extras" that is array. so that the TextBox1 may bind to Person.extras[0], TextBox2 bind to Person.extras[1] and so on...

    Person.extras is treat as a single record, so that every element in Person.extras array is belong to single record. i.e. if i use the CurrencyManager to increment the position, TextBox1 will bind to the next person object extras[0] attribute and TextBox2 will bind to the next person object extras[1] attribute. Since the set of Person object is stored in the List<T> class, it enable CurrencyManager to iterate through. Why i need to spread the data in the Person.extras array is that i need to design the Person object that it may add another attribute for Person object later and fetch this data to the UI. So that the adding and removing of Person attribute can achieve dynamically. Can .NET Data Binding mechanism can do this? and how?

    Thank very much~

    2007年1月28日 下午 12:15