You are viewing our Forum Archives. To view or take place in current topics click here.
Need Help With Visual Studio Combobox not saving items
Posted:
Need Help With Visual Studio Combobox not saving itemsPosted:
Status: Offline
Joined: Feb 13, 201212Year Member
Posts: 59
Reputation Power: 2
Status: Offline
Joined: Feb 13, 201212Year Member
Posts: 59
Reputation Power: 2
Need help combobox is not saving my stuff when i close out and reopen my program items i added reset
how do i make it save to (settings) /(system.collections.specialized.stringcollection)
this is a example program cant get it to save to settings Resets after reopening
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
comboBox1.Items.Add(comboBox1.Text);
}
private void button2_Click(object sender, EventArgs e)
{
comboBox1.Items.Remove(comboBox1.Text);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
how do i make it save to (settings) /(system.collections.specialized.stringcollection)
this is a example program cant get it to save to settings Resets after reopening
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
comboBox1.Items.Add(comboBox1.Text);
}
private void button2_Click(object sender, EventArgs e)
{
comboBox1.Items.Remove(comboBox1.Text);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
#2. Posted:
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Settings are called settings for a reason. They're not meant to store large amounts of data, like form input.
You'll want to iterate through each of the box's items and store them in a format that's meant for storage (xml, sqlite, etc)
You'll want to iterate through each of the box's items and store them in a format that's meant for storage (xml, sqlite, etc)
- 0useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Oct 24, 201311Year Member
Posts: 829
Reputation Power: 150
This is a VB code I'm going to quickly type up, you will need to convert it to your coding language online, its simple!!
Add code:
combobox1.items.add(combobox1.text)
Remove code:
combobox1.items.remove(combobox1.text) or even better!! combobox1.items.remove(combobox1.selecteditem or selectedindex)
Save code:
either do this on closing or when ever you need!
my.settings.combosave.clear or .remove(combobox.items)
THEN!
my.settings.add(combobox1.items)
THEN!
my.settings.save
I hope this helps mate!! Thanks.
Add code:
combobox1.items.add(combobox1.text)
Remove code:
combobox1.items.remove(combobox1.text) or even better!! combobox1.items.remove(combobox1.selecteditem or selectedindex)
Save code:
either do this on closing or when ever you need!
my.settings.combosave.clear or .remove(combobox.items)
THEN!
my.settings.add(combobox1.items)
THEN!
my.settings.save
I hope this helps mate!! Thanks.
- 0useful
- 2not useful
#4. Posted:
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
XeX-ProFlex wrote This is a VB code I'm going to quickly type up, you will need to convert it to your coding language online, its simple!!
Add code:
combobox1.items.add(combobox1.text)
Remove code:
combobox1.items.remove(combobox1.text) or even better!! combobox1.items.remove(combobox1.selecteditem or selectedindex)
Save code:
either do this on closing or when ever you need!
my.settings.combosave.clear or .remove(combobox.items)
THEN!
my.settings.add(combobox1.items)
THEN!
my.settings.save
I hope this helps mate!! Thanks.
Dear god, no. Do not do this....
- 0useful
- 0not useful
#5. Posted:
Status: Offline
Joined: Sep 26, 201014Year Member
Posts: 401
Reputation Power: 17
Status: Offline
Joined: Sep 26, 201014Year Member
Posts: 401
Reputation Power: 17
XeX-ProFlex wrote This is a VB code I'm going to quickly type up, you will need to convert it to your coding language online, its simple!!
Add code:
combobox1.items.add(combobox1.text)
Remove code:
combobox1.items.remove(combobox1.text) or even better!! combobox1.items.remove(combobox1.selecteditem or selectedindex)
Save code:
either do this on closing or when ever you need!
my.settings.combosave.clear or .remove(combobox.items)
THEN!
my.settings.add(combobox1.items)
THEN!
my.settings.save
I hope this helps mate!! Thanks.
Think of this statement as something you shoulf never do.
Speed is right, for something like this I always use XML Visual studios c# makes it pretty easy for you as long as you know the concepts behind xml
- 0useful
- 0not useful
#6. Posted:
Status: Offline
Joined: Oct 24, 201311Year Member
Posts: 829
Reputation Power: 150
whats wrong with my way? its the easiest way its only a quick little code?
- 0useful
- 0not useful
#7. Posted:
Status: Offline
Joined: Jun 29, 201311Year Member
Posts: 211
Reputation Power: 13
Status: Offline
Joined: Jun 29, 201311Year Member
Posts: 211
Reputation Power: 13
Just for future reference, since a lot of people here are responding with "use XML". No, use JSON - XML is ugly and just wastes storage space.
@OP - learn to appropriately name your shit.
@OP - learn to appropriately name your shit.
- 0useful
- 0not useful
#8. Posted:
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
ObscureCoder wrote Just for future reference, since a lot of people here are responding with "use XML". No, use JSON - XML is ugly and just wastes storage space.
@OP - learn to appropriately name your shit.
XML is ugly, but the ugliness serves a purpose. On top of the native XML support that many languages offer, you have full namespace support (which is important for storage). Seeing as OP is most likely not looking to store huge amounts of data, and he is using VB (which supports XML natively), it would likely be the better option.
JSON is built for, and handles very well, data exchange. The same cannot be said for storage. It is quick and clean, at the cost of namespace and datatype capabilities to the likes of XML. You could get away with storing small data (config), but that's not what he wants to do.
- 0useful
- 0not useful
#9. Posted:
Status: Offline
Joined: Jun 29, 201311Year Member
Posts: 211
Reputation Power: 13
Status: Offline
Joined: Jun 29, 201311Year Member
Posts: 211
Reputation Power: 13
speed wroteObscureCoder wrote Just for future reference, since a lot of people here are responding with "use XML". No, use JSON - XML is ugly and just wastes storage space.
@OP - learn to appropriately name your shit.
XML is ugly, but the ugliness serves a purpose. On top of the native XML support that many languages offer, you have full namespace support (which is important for storage). Seeing as OP is most likely not looking to store huge amounts of data, and he is using VB (which supports XML natively), it would likely be the better option.
JSON is built for, and handles very well, data exchange. The same cannot be said for storage. It is quick and clean, at the cost of namespace and datatype capabilities to the likes of XML. You could get away with storing small data (config), but that's not what he wants to do.
[ Register or Signin to view external links. ]
JSON is perfect. It's literally the standardized substitute for XML.
What is OP trying to do? To my understanding, deciphered from his badly articulated thread, he's trying to store settings. It's perfect for that.
- 0useful
- 0not useful
#10. Posted:
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
ObscureCoder wrote What is OP trying to do? To my understanding, deciphered from his badly articulated thread, he's trying to store settings. It's perfect for that.
Good point. I actually have absolutely no idea what he's trying to do. I just assumed based on his code it was some kind of data entry.
With that said, OP, feel free to make another topic with a better explanation of what you're trying to accomplish.
Closed.
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.