Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a List<> containing a class holding different type of variables and I want to display them and interfere with them at the same time. I managed to do this but the way I do this isn't that stable and consumes a lot of time. I want a new way of doing this, a better way with some nice graphics if possible.

So whats the best way of doing this?, writing a whole control or etc...

Here is how I do . . .

public class AListBoxItemToHoldVars
        {
            public string name { get; set; }
            public string hint { get; set; }
            public int amount { get; set; }
        }

        public List<AListBoxItemToHoldVars> mylist = new List<AListBoxItemToHoldVars>();

        
        
        
        private void Form1_Load(object sender, EventArgs e)
        {
            mylist.Add(new AListBoxItemToHoldVars {
                name = "Item 1",
                hint = "This item was created in...",
                amount = 1
            });
        }
        public void refreshlist()
        {
            listBox1.Items.Clear(); // clear the lb
            foreach (AListBoxItemToHoldVars i in mylist) // add them
            {
                mylist.Add(new AListBoxItemToHoldVars
                {
                    name = i.name,
                    hint = i.hint,
                    amount = i.amount
                });
            }
        }
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e) // show the vars in label.text
        {
            if (mylist.Count <= listBox1.Items.Count)
            {
                label1.Text = mylist[listBox1.SelectedIndex].name;
                label1.Text = mylist[listBox1.SelectedIndex].hint;
                label1.Text = mylist[listBox1.SelectedIndex].amount.ToString();
            }
            else
            {
                refreshlist();
            }

        }


EDITED: found my solution in wpf

What I have tried:

My usual way of doing this is using the listbox control with the event "onLBIndexChanged" displaying my variables in labels when the event is triggered.

I also tried to write my own control from scratch. But I can't find a way to do this anywhere. I saw from my searches about modifying a control, like changing a button's border or selection color etc...
Posted
Updated 5-Mar-18 5:30am
v4
Comments
BillWoodruff 4-Mar-18 13:18pm    
Could you clarify what you mean by "interfere," and show the code for the Class, and describe the relationship of the Class to the Labels ?

Also: you have a List of Classes ? Or ?.

1 solution

Quote:
I also tried to write my own control from scratch. But I can't find a way to do this anywhere.

That's easy, just create a UserControl: usercontrol c - Google Search[^]
 
Share this answer
 
Comments
Thaana Paana 5-Mar-18 3:08am    
This isn't from scratch but this could work out, I will try this and let u know.
EDITED:

it didn't work but i found a other solution in wpf user control

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900