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();
foreach (AListBoxItemToHoldVars i in mylist)
{
mylist.Add(new AListBoxItemToHoldVars
{
name = i.name,
hint = i.hint,
amount = i.amount
});
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
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...