user422481
user422481

Reputation: 49

Bind a label in array of labels

I have an array of labels. I use these command lines to bind the Label's text to a column in my table, but it is not binding properly.

Here is the applicable code:

Label[] LL = new Label[26];
for (int i = 0; i < LL.Length; i++)
{
    LL[i] = new Label();
    LL[i].Text = null;
}

LL[0].DataBindings.Add(new System.Windows.Forms.Binding("Text",
                       this.table_010_UserInfoBindingSource, "Column07", true));

Upvotes: 2

Views: 350

Answers (2)

Jason Down
Jason Down

Reputation: 22171

You are only binding the first label in your array. Move the LL[0].Databindings.Add... line up into the for loop. Also, change the LL[0] to LL[i] or you will bind the same label over and over again.

Upvotes: 5

radarbob
radarbob

Reputation: 5101

The DataBinding statement needs to be inside the for loop

Upvotes: 0

Related Questions