none
Display the value of a cell from a dataset as btn.text when another column meets a criteria RRS feed

  • Question

  • I have a program that grabs data from a database server with parameters set from within the program. I set a breakpoint to look at the dataset, and the data is loading properly.

    Column 1 in the dataset contains the "bay" number, and there are 4 buttons on the form (Bay 1, Bay 2, Bay 3, and Bay 4). Column 2 contains the button labels that need to show on the form. When I click the refresh button, the data will download from the server, populate the dataset, and update the four button labels.

    What is the most efficient way to loop through the dataset and set the four button labels to the value of column 2 in that bay's row? The other criteria is that if the column "IsDeleted = True", then it will not display a value.

    I need a Datasets for Dummies book.

    .

    Wednesday, March 14, 2012 4:47 AM

Answers

  • It sounds like your DataSet only contains 4 rows where IsDeleted is false? If so, I'd probably handle this with a DataView, set its RowFilter to filter out the IsDeleted rows, then loop through it and set the button labels. Something like this (off the top of my head):

    DataView dv = new DataView(DataSet1.Tables["AreasSlave"]);
    dv.RowFilter = "IsDeleted = false";
    foreach (DataRow row in dv.Rows)
    {
      switch (row["AreaCode"]) 
      {
        case ("BAY1") :
          lblBay1Counter.Text = row["TicketID"].ToString();
          break;
        case ("BAY2") :
          lblBay2Counter.Text = row["TicketID"].ToString();
          break;
        case ("BAY3") :
          lblBay3Counter.Text = row["TicketID"].ToString();
          break;
        case ("BAY4") :
          lblBay4Counter.Text = row["TicketID"].ToString();
          break;
      }	
    }
    If I'm wrong in my assumption (about the number of rows), then I've misunderstood your question and I'll need more info.

    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Saturday, March 17, 2012 8:20 PM

All replies

  • You need the position property from the bindingsource for that.

    If you have not used the bindingsource than create the currencymanager yourself

    Take a look at this page on our website

    http://www.vb-tips.com/CurrencyManager.aspx


    Success
    Cor

    Thursday, March 15, 2012 11:57 AM
  • It sounds like your DataSet only contains 4 rows where IsDeleted is false? If so, I'd probably handle this with a DataView, set its RowFilter to filter out the IsDeleted rows, then loop through it and set the button labels. Something like this (off the top of my head):

    DataView dv = new DataView(DataSet1.Tables["AreasSlave"]);
    dv.RowFilter = "IsDeleted = false";
    foreach (DataRow row in dv.Rows)
    {
      switch (row["AreaCode"]) 
      {
        case ("BAY1") :
          lblBay1Counter.Text = row["TicketID"].ToString();
          break;
        case ("BAY2") :
          lblBay2Counter.Text = row["TicketID"].ToString();
          break;
        case ("BAY3") :
          lblBay3Counter.Text = row["TicketID"].ToString();
          break;
        case ("BAY4") :
          lblBay4Counter.Text = row["TicketID"].ToString();
          break;
      }	
    }
    If I'm wrong in my assumption (about the number of rows), then I've misunderstood your question and I'll need more info.

    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Saturday, March 17, 2012 8:20 PM
  • Bonnie,

    Thanks for the help. This script works for this particular form. The POS manages which tickets occupy the bays in the database, so I just run a SELECT statement to get the button labels, and the loop script updates the labels for me.

    Now, on the car wash side of the program, which is a little more dynamic and unpredictable. While there is no limit to the number of tickets that can be in an area at a time (we can have as many as 20 vehicles waiting to be vacuumed on a busy day), only the top 12 tickets in the dataset will be displayed. I will set it up so they will be able to scroll if there are 12+ tickets. What I need to know is how to update the properties for a series of controls using a loop. Once I get that, the rest will fall into place. I started a separate thread for Concantenating references to control names on a form during a loop.


    • Edited by slemaire195 Wednesday, March 21, 2012 5:01 AM
    Wednesday, March 21, 2012 4:59 AM
  • I see you've found a solution to your other question in the other thread. That's great! Good luck with your project!


    ~~Bonnie Berent DeWitt [C# MVP]

    geek-goddess-bonnie.blogspot.com

    Wednesday, March 21, 2012 1:49 PM