Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Keep track of rows in dynamically created controls

$
0
0

Hello

I create controls in a form dynamicly in an edit form

foreach(var item in list){

TextBox textBoxName = new TextBox();
CheckBox checkBoxYesOrNo = new CheckBox();

 textBoxName.Name = "Name" + item.id.ToString();
                textBoxName.Text = item.name;
                checkBoxPing.Text = "Yes";
                checkBoxPing.Name = "Yes" + item.id.ToString();
                checkBoxPing.Checked = item.checked;

//It would be nice to add item.id each row somehow
}


and on buttonclick I loop the controls to update the values in List

foreach (Control c in this.Controls)
            {

//Is it possible to do somekind of (pseudo)
if(row.id == itemInList.id){
//Then I know which object we're talking about 
//and adjust Name,YesOrNo values etc for that object
}

}

But it would be nice to be able to know what object in list is treated when looping each row.

In php when doing web programming I could add a css id to each row, or even a hidden value to each control with id of the object, item.id

Regards



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>