How do you populate a list with a structure at form load in C#
I'm just flat out lost. What I need to do is get the structure, specifically cookie name to populate the list box. Than when i click on the selected item it should change the data in the labels... there is more to it but this is where I am right now. Yes it's homework but I'm also in my 30's with a good job. I'm just trying to learn this stuff so I might be able to use it in my hobbies. So please only help no snark about "do your own homework."
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Unit_8_Cookie_Scouts
{
struct CookieStruct
{
public string cookieName;
public decimal cookiePrice;
public int inventoryNum;
public decimal valueOfInventory;
}
public partial class CookeScouts : Form
{
//create a List as a field
private List<CookieStruct> cookieList = new List<CookieStruct>();
List<string> cookieName = new List<string>() { "Peppermint Flatties", "Chocolate Chippers", "Pecan Paradise", "Sugary Shortcake" };
List<decimal> cookiePrice = new List<decimal>() { 4.99m, 4.76m, 6.82m, 5.99m };
List<int> inventoryNum = new List<int>() { 8, 17, 9, 12 };
List<decimal> valueOfInventory = new List<decimal>() { 39.92m, 80.92m, 61.38m, 71.88m };
public CookeScouts()
{
InitializeComponent();
int Index = lstCookies.SelectedIndex;
//update values with index 0
tempInfo.cookieName = cookieName(0);
//create a temp structure object to add values too
CookieStruct tempInfo = new CookieStruct();
//add temp structure object to list at form level
tempInfo.cookieName = cookieName(Index).Text;
//add temp structure to list at form level
cookieList.Add(tempInfo);
for (int index = 0; index < cookieList.Count; index++)
{
lstCookies.Items.Add(index);
}
LoadListBox();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////// METHODS /////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void LoadListBox()
{
string output;
//loop through and add to combo box
foreach (CookieStruct tempInfo in cookieList)
{
//make output line for combo box
output = tempInfo.cookieName;
//send the output to combo box cboCustomers
lstCookies.Items.Add(output);
}
}
}
}
//////////////////////////////CLASS//////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Unit_8_Cookie_Scouts
{
class clsCookies
{
//delcare variables
string _ItemType;
decimal _Price;
decimal _Inventory;
decimal _Value;
//new instance of class
public clsCookies()
{
_ItemType = "";
_Price = 0;
_Inventory = 0;
_Value = 0;
}
public clsCookies(string CookieName, decimal CookiePrice, decimal InvAmount, decimal TotalValue)
{
_ItemType = CookieName;
_Price = CookiePrice;
_Inventory = InvAmount;
_Value = TotalValue;
}
//properties
public string CookieType
{
get { return _ItemType; }
set { _ItemType = value; }
}
public decimal Price
{
get { return _Price; }
set { _Price = value; }
}
public decimal Inventory
{
get { return _Inventory; }
set { _Inventory = value; }
}
public decimal Value
{
get
{
return _Value;
}
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// METHODS ///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
public void UpdateInventory(int InvChanged)
{
_Inventory += InvChanged;
}
public void UpdateValue(decimal ValueChanged)
{
_Value = _Price * _Inventory;
}
}
}
c# list structure
|
show 1 more comment
I'm just flat out lost. What I need to do is get the structure, specifically cookie name to populate the list box. Than when i click on the selected item it should change the data in the labels... there is more to it but this is where I am right now. Yes it's homework but I'm also in my 30's with a good job. I'm just trying to learn this stuff so I might be able to use it in my hobbies. So please only help no snark about "do your own homework."
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Unit_8_Cookie_Scouts
{
struct CookieStruct
{
public string cookieName;
public decimal cookiePrice;
public int inventoryNum;
public decimal valueOfInventory;
}
public partial class CookeScouts : Form
{
//create a List as a field
private List<CookieStruct> cookieList = new List<CookieStruct>();
List<string> cookieName = new List<string>() { "Peppermint Flatties", "Chocolate Chippers", "Pecan Paradise", "Sugary Shortcake" };
List<decimal> cookiePrice = new List<decimal>() { 4.99m, 4.76m, 6.82m, 5.99m };
List<int> inventoryNum = new List<int>() { 8, 17, 9, 12 };
List<decimal> valueOfInventory = new List<decimal>() { 39.92m, 80.92m, 61.38m, 71.88m };
public CookeScouts()
{
InitializeComponent();
int Index = lstCookies.SelectedIndex;
//update values with index 0
tempInfo.cookieName = cookieName(0);
//create a temp structure object to add values too
CookieStruct tempInfo = new CookieStruct();
//add temp structure object to list at form level
tempInfo.cookieName = cookieName(Index).Text;
//add temp structure to list at form level
cookieList.Add(tempInfo);
for (int index = 0; index < cookieList.Count; index++)
{
lstCookies.Items.Add(index);
}
LoadListBox();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////// METHODS /////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void LoadListBox()
{
string output;
//loop through and add to combo box
foreach (CookieStruct tempInfo in cookieList)
{
//make output line for combo box
output = tempInfo.cookieName;
//send the output to combo box cboCustomers
lstCookies.Items.Add(output);
}
}
}
}
//////////////////////////////CLASS//////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Unit_8_Cookie_Scouts
{
class clsCookies
{
//delcare variables
string _ItemType;
decimal _Price;
decimal _Inventory;
decimal _Value;
//new instance of class
public clsCookies()
{
_ItemType = "";
_Price = 0;
_Inventory = 0;
_Value = 0;
}
public clsCookies(string CookieName, decimal CookiePrice, decimal InvAmount, decimal TotalValue)
{
_ItemType = CookieName;
_Price = CookiePrice;
_Inventory = InvAmount;
_Value = TotalValue;
}
//properties
public string CookieType
{
get { return _ItemType; }
set { _ItemType = value; }
}
public decimal Price
{
get { return _Price; }
set { _Price = value; }
}
public decimal Inventory
{
get { return _Inventory; }
set { _Inventory = value; }
}
public decimal Value
{
get
{
return _Value;
}
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// METHODS ///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
public void UpdateInventory(int InvChanged)
{
_Inventory += InvChanged;
}
public void UpdateValue(decimal ValueChanged)
{
_Value = _Price * _Inventory;
}
}
}
c# list structure
If you want to use DataBinding (AKA the easy way), you'll want to convert the structure to a class with properties
– WelcomeOverflow
Nov 11 at 20:22
You need to create cookie struct objects and not create seperate list..
– Aldert
Nov 11 at 20:25
Isn't that what I did? I made the structure than defined each part?
– Ravenna Lacroix
Nov 11 at 20:28
I made a class too...
– Ravenna Lacroix
Nov 11 at 20:29
I added the class to what I did.
– Ravenna Lacroix
Nov 11 at 20:32
|
show 1 more comment
I'm just flat out lost. What I need to do is get the structure, specifically cookie name to populate the list box. Than when i click on the selected item it should change the data in the labels... there is more to it but this is where I am right now. Yes it's homework but I'm also in my 30's with a good job. I'm just trying to learn this stuff so I might be able to use it in my hobbies. So please only help no snark about "do your own homework."
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Unit_8_Cookie_Scouts
{
struct CookieStruct
{
public string cookieName;
public decimal cookiePrice;
public int inventoryNum;
public decimal valueOfInventory;
}
public partial class CookeScouts : Form
{
//create a List as a field
private List<CookieStruct> cookieList = new List<CookieStruct>();
List<string> cookieName = new List<string>() { "Peppermint Flatties", "Chocolate Chippers", "Pecan Paradise", "Sugary Shortcake" };
List<decimal> cookiePrice = new List<decimal>() { 4.99m, 4.76m, 6.82m, 5.99m };
List<int> inventoryNum = new List<int>() { 8, 17, 9, 12 };
List<decimal> valueOfInventory = new List<decimal>() { 39.92m, 80.92m, 61.38m, 71.88m };
public CookeScouts()
{
InitializeComponent();
int Index = lstCookies.SelectedIndex;
//update values with index 0
tempInfo.cookieName = cookieName(0);
//create a temp structure object to add values too
CookieStruct tempInfo = new CookieStruct();
//add temp structure object to list at form level
tempInfo.cookieName = cookieName(Index).Text;
//add temp structure to list at form level
cookieList.Add(tempInfo);
for (int index = 0; index < cookieList.Count; index++)
{
lstCookies.Items.Add(index);
}
LoadListBox();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////// METHODS /////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void LoadListBox()
{
string output;
//loop through and add to combo box
foreach (CookieStruct tempInfo in cookieList)
{
//make output line for combo box
output = tempInfo.cookieName;
//send the output to combo box cboCustomers
lstCookies.Items.Add(output);
}
}
}
}
//////////////////////////////CLASS//////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Unit_8_Cookie_Scouts
{
class clsCookies
{
//delcare variables
string _ItemType;
decimal _Price;
decimal _Inventory;
decimal _Value;
//new instance of class
public clsCookies()
{
_ItemType = "";
_Price = 0;
_Inventory = 0;
_Value = 0;
}
public clsCookies(string CookieName, decimal CookiePrice, decimal InvAmount, decimal TotalValue)
{
_ItemType = CookieName;
_Price = CookiePrice;
_Inventory = InvAmount;
_Value = TotalValue;
}
//properties
public string CookieType
{
get { return _ItemType; }
set { _ItemType = value; }
}
public decimal Price
{
get { return _Price; }
set { _Price = value; }
}
public decimal Inventory
{
get { return _Inventory; }
set { _Inventory = value; }
}
public decimal Value
{
get
{
return _Value;
}
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// METHODS ///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
public void UpdateInventory(int InvChanged)
{
_Inventory += InvChanged;
}
public void UpdateValue(decimal ValueChanged)
{
_Value = _Price * _Inventory;
}
}
}
c# list structure
I'm just flat out lost. What I need to do is get the structure, specifically cookie name to populate the list box. Than when i click on the selected item it should change the data in the labels... there is more to it but this is where I am right now. Yes it's homework but I'm also in my 30's with a good job. I'm just trying to learn this stuff so I might be able to use it in my hobbies. So please only help no snark about "do your own homework."
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Unit_8_Cookie_Scouts
{
struct CookieStruct
{
public string cookieName;
public decimal cookiePrice;
public int inventoryNum;
public decimal valueOfInventory;
}
public partial class CookeScouts : Form
{
//create a List as a field
private List<CookieStruct> cookieList = new List<CookieStruct>();
List<string> cookieName = new List<string>() { "Peppermint Flatties", "Chocolate Chippers", "Pecan Paradise", "Sugary Shortcake" };
List<decimal> cookiePrice = new List<decimal>() { 4.99m, 4.76m, 6.82m, 5.99m };
List<int> inventoryNum = new List<int>() { 8, 17, 9, 12 };
List<decimal> valueOfInventory = new List<decimal>() { 39.92m, 80.92m, 61.38m, 71.88m };
public CookeScouts()
{
InitializeComponent();
int Index = lstCookies.SelectedIndex;
//update values with index 0
tempInfo.cookieName = cookieName(0);
//create a temp structure object to add values too
CookieStruct tempInfo = new CookieStruct();
//add temp structure object to list at form level
tempInfo.cookieName = cookieName(Index).Text;
//add temp structure to list at form level
cookieList.Add(tempInfo);
for (int index = 0; index < cookieList.Count; index++)
{
lstCookies.Items.Add(index);
}
LoadListBox();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////// METHODS /////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void LoadListBox()
{
string output;
//loop through and add to combo box
foreach (CookieStruct tempInfo in cookieList)
{
//make output line for combo box
output = tempInfo.cookieName;
//send the output to combo box cboCustomers
lstCookies.Items.Add(output);
}
}
}
}
//////////////////////////////CLASS//////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Unit_8_Cookie_Scouts
{
class clsCookies
{
//delcare variables
string _ItemType;
decimal _Price;
decimal _Inventory;
decimal _Value;
//new instance of class
public clsCookies()
{
_ItemType = "";
_Price = 0;
_Inventory = 0;
_Value = 0;
}
public clsCookies(string CookieName, decimal CookiePrice, decimal InvAmount, decimal TotalValue)
{
_ItemType = CookieName;
_Price = CookiePrice;
_Inventory = InvAmount;
_Value = TotalValue;
}
//properties
public string CookieType
{
get { return _ItemType; }
set { _ItemType = value; }
}
public decimal Price
{
get { return _Price; }
set { _Price = value; }
}
public decimal Inventory
{
get { return _Inventory; }
set { _Inventory = value; }
}
public decimal Value
{
get
{
return _Value;
}
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// METHODS ///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
public void UpdateInventory(int InvChanged)
{
_Inventory += InvChanged;
}
public void UpdateValue(decimal ValueChanged)
{
_Value = _Price * _Inventory;
}
}
}
c# list structure
c# list structure
edited Nov 11 at 20:31
asked Nov 11 at 20:02
Ravenna Lacroix
33
33
If you want to use DataBinding (AKA the easy way), you'll want to convert the structure to a class with properties
– WelcomeOverflow
Nov 11 at 20:22
You need to create cookie struct objects and not create seperate list..
– Aldert
Nov 11 at 20:25
Isn't that what I did? I made the structure than defined each part?
– Ravenna Lacroix
Nov 11 at 20:28
I made a class too...
– Ravenna Lacroix
Nov 11 at 20:29
I added the class to what I did.
– Ravenna Lacroix
Nov 11 at 20:32
|
show 1 more comment
If you want to use DataBinding (AKA the easy way), you'll want to convert the structure to a class with properties
– WelcomeOverflow
Nov 11 at 20:22
You need to create cookie struct objects and not create seperate list..
– Aldert
Nov 11 at 20:25
Isn't that what I did? I made the structure than defined each part?
– Ravenna Lacroix
Nov 11 at 20:28
I made a class too...
– Ravenna Lacroix
Nov 11 at 20:29
I added the class to what I did.
– Ravenna Lacroix
Nov 11 at 20:32
If you want to use DataBinding (AKA the easy way), you'll want to convert the structure to a class with properties
– WelcomeOverflow
Nov 11 at 20:22
If you want to use DataBinding (AKA the easy way), you'll want to convert the structure to a class with properties
– WelcomeOverflow
Nov 11 at 20:22
You need to create cookie struct objects and not create seperate list..
– Aldert
Nov 11 at 20:25
You need to create cookie struct objects and not create seperate list..
– Aldert
Nov 11 at 20:25
Isn't that what I did? I made the structure than defined each part?
– Ravenna Lacroix
Nov 11 at 20:28
Isn't that what I did? I made the structure than defined each part?
– Ravenna Lacroix
Nov 11 at 20:28
I made a class too...
– Ravenna Lacroix
Nov 11 at 20:29
I made a class too...
– Ravenna Lacroix
Nov 11 at 20:29
I added the class to what I did.
– Ravenna Lacroix
Nov 11 at 20:32
I added the class to what I did.
– Ravenna Lacroix
Nov 11 at 20:32
|
show 1 more comment
1 Answer
1
active
oldest
votes
Have a look at the answer, should help you..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Unit_8_Cookie_Scouts
{
struct CookieStruct
{
public string cookieName;
public decimal cookiePrice;
public int inventoryNum;
public decimal valueOfInventory;
}
public partial class CookeScouts : Form
{
//create a List as a field
private List<CookieStruct> cookieList = new List<CookieStruct>();
public CookeScouts()
{
InitializeComponent();
cookieList.Add(new CookieStruct() { cookieName = "Peppermint Flatties", cookiePrice = 4.99m, inventoryNum = 8, valueOfInventory = 39.92m });
cookieList.Add(new CookieStruct() { cookieName = "Chocolate Chippers", cookiePrice = 4.76m, inventoryNum = 17, valueOfInventory = 80.92m });
cookieList.Add(new CookieStruct() { cookieName = "Pecan Paradise", cookiePrice = 6.82m, inventoryNum = 9, valueOfInventory = 61.38m });
cookieList.Add(new CookieStruct() { cookieName = "Sugary Shortcake", cookiePrice = 5.99m, inventoryNum = 12, valueOfInventory = 71.88m });
LoadListBox();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
int Index = lstCookies.SelectedIndex;
//update values with index 0
tempInfo.cookieName = cookieList[Index].cookieName;
//create a temp structure object to add values too
}
private void LoadListBox()
{
string output;
//loop through and add to combo box
foreach (CookieStruct tempInfo in cookieList)
{
//make output line for combo box
output = tempInfo.cookieName;
//send the output to combo box cboCustomers
lstCookies.Items.Add(output);
}
}
}
}
okay that makes sense. Thank you. The book didn't show anything like this.... honestly the examples are like coin flips and stuff it's really unhelpful.
– Ravenna Lacroix
Nov 11 at 21:15
You are welcome, please mark question as answered.
– Aldert
Nov 12 at 7:18
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252690%2fhow-do-you-populate-a-list-with-a-structure-at-form-load-in-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Have a look at the answer, should help you..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Unit_8_Cookie_Scouts
{
struct CookieStruct
{
public string cookieName;
public decimal cookiePrice;
public int inventoryNum;
public decimal valueOfInventory;
}
public partial class CookeScouts : Form
{
//create a List as a field
private List<CookieStruct> cookieList = new List<CookieStruct>();
public CookeScouts()
{
InitializeComponent();
cookieList.Add(new CookieStruct() { cookieName = "Peppermint Flatties", cookiePrice = 4.99m, inventoryNum = 8, valueOfInventory = 39.92m });
cookieList.Add(new CookieStruct() { cookieName = "Chocolate Chippers", cookiePrice = 4.76m, inventoryNum = 17, valueOfInventory = 80.92m });
cookieList.Add(new CookieStruct() { cookieName = "Pecan Paradise", cookiePrice = 6.82m, inventoryNum = 9, valueOfInventory = 61.38m });
cookieList.Add(new CookieStruct() { cookieName = "Sugary Shortcake", cookiePrice = 5.99m, inventoryNum = 12, valueOfInventory = 71.88m });
LoadListBox();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
int Index = lstCookies.SelectedIndex;
//update values with index 0
tempInfo.cookieName = cookieList[Index].cookieName;
//create a temp structure object to add values too
}
private void LoadListBox()
{
string output;
//loop through and add to combo box
foreach (CookieStruct tempInfo in cookieList)
{
//make output line for combo box
output = tempInfo.cookieName;
//send the output to combo box cboCustomers
lstCookies.Items.Add(output);
}
}
}
}
okay that makes sense. Thank you. The book didn't show anything like this.... honestly the examples are like coin flips and stuff it's really unhelpful.
– Ravenna Lacroix
Nov 11 at 21:15
You are welcome, please mark question as answered.
– Aldert
Nov 12 at 7:18
add a comment |
Have a look at the answer, should help you..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Unit_8_Cookie_Scouts
{
struct CookieStruct
{
public string cookieName;
public decimal cookiePrice;
public int inventoryNum;
public decimal valueOfInventory;
}
public partial class CookeScouts : Form
{
//create a List as a field
private List<CookieStruct> cookieList = new List<CookieStruct>();
public CookeScouts()
{
InitializeComponent();
cookieList.Add(new CookieStruct() { cookieName = "Peppermint Flatties", cookiePrice = 4.99m, inventoryNum = 8, valueOfInventory = 39.92m });
cookieList.Add(new CookieStruct() { cookieName = "Chocolate Chippers", cookiePrice = 4.76m, inventoryNum = 17, valueOfInventory = 80.92m });
cookieList.Add(new CookieStruct() { cookieName = "Pecan Paradise", cookiePrice = 6.82m, inventoryNum = 9, valueOfInventory = 61.38m });
cookieList.Add(new CookieStruct() { cookieName = "Sugary Shortcake", cookiePrice = 5.99m, inventoryNum = 12, valueOfInventory = 71.88m });
LoadListBox();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
int Index = lstCookies.SelectedIndex;
//update values with index 0
tempInfo.cookieName = cookieList[Index].cookieName;
//create a temp structure object to add values too
}
private void LoadListBox()
{
string output;
//loop through and add to combo box
foreach (CookieStruct tempInfo in cookieList)
{
//make output line for combo box
output = tempInfo.cookieName;
//send the output to combo box cboCustomers
lstCookies.Items.Add(output);
}
}
}
}
okay that makes sense. Thank you. The book didn't show anything like this.... honestly the examples are like coin flips and stuff it's really unhelpful.
– Ravenna Lacroix
Nov 11 at 21:15
You are welcome, please mark question as answered.
– Aldert
Nov 12 at 7:18
add a comment |
Have a look at the answer, should help you..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Unit_8_Cookie_Scouts
{
struct CookieStruct
{
public string cookieName;
public decimal cookiePrice;
public int inventoryNum;
public decimal valueOfInventory;
}
public partial class CookeScouts : Form
{
//create a List as a field
private List<CookieStruct> cookieList = new List<CookieStruct>();
public CookeScouts()
{
InitializeComponent();
cookieList.Add(new CookieStruct() { cookieName = "Peppermint Flatties", cookiePrice = 4.99m, inventoryNum = 8, valueOfInventory = 39.92m });
cookieList.Add(new CookieStruct() { cookieName = "Chocolate Chippers", cookiePrice = 4.76m, inventoryNum = 17, valueOfInventory = 80.92m });
cookieList.Add(new CookieStruct() { cookieName = "Pecan Paradise", cookiePrice = 6.82m, inventoryNum = 9, valueOfInventory = 61.38m });
cookieList.Add(new CookieStruct() { cookieName = "Sugary Shortcake", cookiePrice = 5.99m, inventoryNum = 12, valueOfInventory = 71.88m });
LoadListBox();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
int Index = lstCookies.SelectedIndex;
//update values with index 0
tempInfo.cookieName = cookieList[Index].cookieName;
//create a temp structure object to add values too
}
private void LoadListBox()
{
string output;
//loop through and add to combo box
foreach (CookieStruct tempInfo in cookieList)
{
//make output line for combo box
output = tempInfo.cookieName;
//send the output to combo box cboCustomers
lstCookies.Items.Add(output);
}
}
}
}
Have a look at the answer, should help you..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Unit_8_Cookie_Scouts
{
struct CookieStruct
{
public string cookieName;
public decimal cookiePrice;
public int inventoryNum;
public decimal valueOfInventory;
}
public partial class CookeScouts : Form
{
//create a List as a field
private List<CookieStruct> cookieList = new List<CookieStruct>();
public CookeScouts()
{
InitializeComponent();
cookieList.Add(new CookieStruct() { cookieName = "Peppermint Flatties", cookiePrice = 4.99m, inventoryNum = 8, valueOfInventory = 39.92m });
cookieList.Add(new CookieStruct() { cookieName = "Chocolate Chippers", cookiePrice = 4.76m, inventoryNum = 17, valueOfInventory = 80.92m });
cookieList.Add(new CookieStruct() { cookieName = "Pecan Paradise", cookiePrice = 6.82m, inventoryNum = 9, valueOfInventory = 61.38m });
cookieList.Add(new CookieStruct() { cookieName = "Sugary Shortcake", cookiePrice = 5.99m, inventoryNum = 12, valueOfInventory = 71.88m });
LoadListBox();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
int Index = lstCookies.SelectedIndex;
//update values with index 0
tempInfo.cookieName = cookieList[Index].cookieName;
//create a temp structure object to add values too
}
private void LoadListBox()
{
string output;
//loop through and add to combo box
foreach (CookieStruct tempInfo in cookieList)
{
//make output line for combo box
output = tempInfo.cookieName;
//send the output to combo box cboCustomers
lstCookies.Items.Add(output);
}
}
}
}
answered Nov 11 at 20:39
Aldert
1,0381212
1,0381212
okay that makes sense. Thank you. The book didn't show anything like this.... honestly the examples are like coin flips and stuff it's really unhelpful.
– Ravenna Lacroix
Nov 11 at 21:15
You are welcome, please mark question as answered.
– Aldert
Nov 12 at 7:18
add a comment |
okay that makes sense. Thank you. The book didn't show anything like this.... honestly the examples are like coin flips and stuff it's really unhelpful.
– Ravenna Lacroix
Nov 11 at 21:15
You are welcome, please mark question as answered.
– Aldert
Nov 12 at 7:18
okay that makes sense. Thank you. The book didn't show anything like this.... honestly the examples are like coin flips and stuff it's really unhelpful.
– Ravenna Lacroix
Nov 11 at 21:15
okay that makes sense. Thank you. The book didn't show anything like this.... honestly the examples are like coin flips and stuff it's really unhelpful.
– Ravenna Lacroix
Nov 11 at 21:15
You are welcome, please mark question as answered.
– Aldert
Nov 12 at 7:18
You are welcome, please mark question as answered.
– Aldert
Nov 12 at 7:18
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252690%2fhow-do-you-populate-a-list-with-a-structure-at-form-load-in-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If you want to use DataBinding (AKA the easy way), you'll want to convert the structure to a class with properties
– WelcomeOverflow
Nov 11 at 20:22
You need to create cookie struct objects and not create seperate list..
– Aldert
Nov 11 at 20:25
Isn't that what I did? I made the structure than defined each part?
– Ravenna Lacroix
Nov 11 at 20:28
I made a class too...
– Ravenna Lacroix
Nov 11 at 20:29
I added the class to what I did.
– Ravenna Lacroix
Nov 11 at 20:32