C
C#2y ago
SAFE

❔ Help with Lists/Combobox

public partial class Form1 : Form { const decimal SALES_TAX_RATE = 0.15m; // private List<Order> orders = new List<Order>(){"Potatos"}; // string[] genres = { "Blues", "Country", "Hip Hop", "Easy Listening", "Rock", "Pop" }; // List<Order> order = new List<Order>(genres); string[] genres = { "Blues", "Country", "Hip Hop", "Easy Listening", "Rock", "Pop" }; List<Order> orders = new List<Order>(); public Form1() { InitializeComponent(); } //string[] genres = new string[] // { // "Blues", // "Country", // "Easy Listening", /// "Hip Hop", // "Rock", // "Pop" // }; #region Methods private void ResetForm() { cboGenres.SelectedIndex = -1; txtAlbumName.Text = ""; txtArtistName.Text = ""; txtQuantity.Text = ""; txtPrice.Text = ""; txtArtistName.Focus(); } public void LoadGenres() { for (int i = 0; i < genres.Length; i++) { cboGenres.Items.Add(genres[i]); } } private void Form1_Load(object sender, EventArgs e) { LoadGenres(); }
27 Replies
SAFE
SAFEOP2y ago
for some reason, the list wont show up in my combobox theres no actual errors in the code and it does run, so im not sure what it is
Pobiega
Pobiega2y ago
$codegif
Pobiega
Pobiega2y ago
and please remove the commented out duplicate code, it just makes reading really hard at a glance, it seems okay. Are you sure the Form1_Load event is firing? use the debugger to make sure
SAFE
SAFEOP2y ago
ok ill try, also maybe its cause i havent got to a certain part of assignment yet where i have to do something else to add it idk yes it form loads but the combox has nothing
Pobiega
Pobiega2y ago
read that again I didn't ask if the form loads. I asked if Form1_Load actually triggers. If you have not wired up the event subscription for that method, it wont.
SAFE
SAFEOP2y ago
um.. how can i tell if it triggers im new ish sorry or could i just copy my code into a second downloaded copy of the starter file and it would work?
Pobiega
Pobiega2y ago
You would use your debugger. Set a breakpoint in visual studio $debug
MODiX
MODiX2y ago
Tutorial: Debug C# code - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
SAFE
SAFEOP2y ago
ok so i believe that it is triggering
ACiDCA7
ACiDCA72y ago
can you amke a screenshot of how the brakpoint was reached inside LoadGenres because your last message doesnt sound really convincing
SAFE
SAFEOP2y ago
ok sure also i just download the assignment starter again and copied everything and it still wont show the combobox list, so its the code i think but idk lol all was the same but that
SAFE
SAFEOP2y ago
SAFE
SAFEOP2y ago
loadgenres method
ACiDCA7
ACiDCA72y ago
you are just showing your code.. i wanted you to show me that the breakpoint in the right spot is getting reached.. for that you have to start your app the red dot should go into loadgenre
SAFE
SAFEOP2y ago
thought you meant breakpoint in the code, what do you mean ok
ACiDCA7
ACiDCA72y ago
now that its in there start your app
SAFE
SAFEOP2y ago
nothing in the combobox still i put the dot at line 83 at the loadgenres method
ACiDCA7
ACiDCA72y ago
if you havent noticed any "weird" behavior i guess the method is never called that means the form_load method is never excecuted which means you have messed something up in the designer of the form
SAFE
SAFEOP2y ago
omg im dumb i just double click form on the designer so it would actually show up
ACiDCA7
ACiDCA72y ago
could you phrase it so that people who arent sitting right next to you understand what you mean
SAFE
SAFEOP2y ago
LOL one more thing in it that needs to be fixed: '
SAFE
SAFEOP2y ago
SAFE
SAFEOP2y ago
shows that it isnt valid no matter what
ACiDCA7
ACiDCA72y ago
i see that genre is populated now... for that problem someone else can help you if you need more assistance
SAFE
SAFEOP2y ago
alright okok
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server