rog_rickert
Member
- Joined
- Dec 17, 2020
- Messages
- 11
- Programming Experience
- Beginner
Hello, looking for advice on an issue. What I have is working, I'm just wondering if there is an easier way to implement it. On a form in my project I have a tabcontrol with 4 tag pages for Channels 1-4. Each tab page has the same controls on it and are populated with values from a list of objects. Here's some shortened code to help better illustrate what I'm doing:
On each tab, say I have 3 textboxes. leading to 12 total (txtApple1,txtApple2,txtApple3, txtApple4, txtOrange 1.......txtGrape4)
Right now, I'm populating the textboxes manually on each form like:
Like I said this works, but this is only a representation with a simple example. My project has more fields and controls that I'm working with, so I was hoping there'd be a way to do something to reference them by index. I know my controls aren't indexed, I'm just trying to illustrate what I'd like to do.
Any help is appreciated.
C#:
//class with fields:
public class ChannelFields
{
public string apple;
public string orange;
public string grape;
}
// Create List of Channel objects with fields from ChannelFields
public static List<ChannelFields> Channel = new List<ChannelFields>(4)
{
new ChannelFields(),
new ChannelFields(),
new ChannelFields(),
new ChannelFields(),
};
Right now, I'm populating the textboxes manually on each form like:
C#:
txtApple1.text = Channel[0].apple;
txtApple2.text = Channel[1].apple;
// ...
txtGrape4.text = Channel[3].grape;
C#:
for(int ch =-0; ch<4;ch++)
{
int tab = ch + 1;
txtApple[tab].text = Channel[ch].apple;
txtOrange[tab].text = Channel[ch].orange;
txtGrape[tab].text = Channel[ch].grape;
}
Last edited by a moderator: