-2

why I do not get anything in my textbox when I run the program? I have my methods in class can anybody give me any hint I can solve this issue.

MainWin code

   *List<Card> cards = new List<Card>();

    DBManager dB = new DBManager();
    public MainWindow()
    {
        Card card = new Card();

        InitializeComponent();
        dB.GetCards(cards);
        txtQuestion.Text = card.Question;
        lblCardsList.ItemsSource = cards;
        GetRandomCards();
        DisplayCardQuestion();

    }

    private void GetRandomCards()
    {
        Card card = new Card();
        Random random = new Random();
        int rndCard = random.Next(1, 100);
        for (int i = 0; i < rndCard; i++)
        {
           cards.Add(card);
        }


    }
    private void DisplayCardQuestion()
    {
        Card card = new Card();

            lblCardNum.Content =card.CardID;
            txtQuestion.Text = card.Question;
            txtTitle.Text = card.Title;

       }*
Obaidi
  • 1
  • 3

1 Answers1

1

I would assume that dB.GetCards(cards) returns a List<Card>. If that is the case, use cards = dB.GetCards(cards); instead.

Also, in your GetRandomCard method, it's going to add the same card onto your cards List rndCard times. If you're trying to pick a Random Card from cards, you should rethink your logic.

Brett Wertz
  • 412
  • 4
  • 19
  • I tried cards = dB.GetCards(cards); but did not work – Obaidi Apr 20 '20 at 23:31
  • There are just too many unknowns with this. Like, what do the `DBManager` and `Card` classes actually do and are they actually instantiated correctly? I'm not asking you to answer that question here but would rather ask that you debug it in Visual Studio and set break points to step through every method that you wrote and validate what is actually going on. Good luck! – Brett Wertz Apr 22 '20 at 09:39