Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Data labels ?

Data labels ?

Scheduled Pinned Locked Moved C#
databasesecurityhelpquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SRJ92
    wrote on last edited by
    #1

    sorry, my other post wasn't clear ... hello, i want to create a more complex highscore board that displays the playname and score in labels! currently i have a datagrid which is displaying my data as a test, here is my code for that:

            OLEDataConnector Dat = new OLEDataConnector("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\"Highscore.accdb\\";Persist Security Info=False;");
            DataTable Dt = new DataTable();
            Dat.dataSelect("select Playername, Score, LevelNumber from score order by score desc", ref Dt);
            dataGridView1.DataSource = Dt.DefaultView;
    

    its a microsoft access database and i need to get around 10 rows if they are in the database to be put onto my highscore board ... So what i want is the playername of the record to be put into one label and the other as a score in another label, obviosuly they will move around using the query, :P Any help? as i can't find anything on this that is of any use.... Thanks

    D H 2 Replies Last reply
    0
    • S SRJ92

      sorry, my other post wasn't clear ... hello, i want to create a more complex highscore board that displays the playname and score in labels! currently i have a datagrid which is displaying my data as a test, here is my code for that:

              OLEDataConnector Dat = new OLEDataConnector("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\"Highscore.accdb\\";Persist Security Info=False;");
              DataTable Dt = new DataTable();
              Dat.dataSelect("select Playername, Score, LevelNumber from score order by score desc", ref Dt);
              dataGridView1.DataSource = Dt.DefaultView;
      

      its a microsoft access database and i need to get around 10 rows if they are in the database to be put onto my highscore board ... So what i want is the playername of the record to be put into one label and the other as a score in another label, obviosuly they will move around using the query, :P Any help? as i can't find anything on this that is of any use.... Thanks

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Why use labels at all? Why not just get the data and draw the text on a panel yourself? You can't bind a list of data to automatically create an array of labels for you. You have to copy the text from each record from the database to each label where it belongs. It's easier to just draw it yourself.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      1 Reply Last reply
      0
      • S SRJ92

        sorry, my other post wasn't clear ... hello, i want to create a more complex highscore board that displays the playname and score in labels! currently i have a datagrid which is displaying my data as a test, here is my code for that:

                OLEDataConnector Dat = new OLEDataConnector("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\"Highscore.accdb\\";Persist Security Info=False;");
                DataTable Dt = new DataTable();
                Dat.dataSelect("select Playername, Score, LevelNumber from score order by score desc", ref Dt);
                dataGridView1.DataSource = Dt.DefaultView;
        

        its a microsoft access database and i need to get around 10 rows if they are in the database to be put onto my highscore board ... So what i want is the playername of the record to be put into one label and the other as a score in another label, obviosuly they will move around using the query, :P Any help? as i can't find anything on this that is of any use.... Thanks

        H Offline
        H Offline
        Henry Minute
        wrote on last edited by
        #3

        Well the DataTable that you have created in your code has a Rows[^] property. What you can do is iterate over this collection (there is an example in the link above) and for each DataRow, create your two Labels and add them to your form. You will have to keep track of the X and Y coordinates so that you can position them properly. I could write the code out for you, but that really wouldn't help you learn. Have a go and if you get stuck, or you don't understand, please come back to me. Good luck. :)

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        S 2 Replies Last reply
        0
        • H Henry Minute

          Well the DataTable that you have created in your code has a Rows[^] property. What you can do is iterate over this collection (there is an example in the link above) and for each DataRow, create your two Labels and add them to your form. You will have to keep track of the X and Y coordinates so that you can position them properly. I could write the code out for you, but that really wouldn't help you learn. Have a go and if you get stuck, or you don't understand, please come back to me. Good luck. :)

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

          S Offline
          S Offline
          SRJ92
          wrote on last edited by
          #4

          Thank you i shall try that :P

          1 Reply Last reply
          0
          • H Henry Minute

            Well the DataTable that you have created in your code has a Rows[^] property. What you can do is iterate over this collection (there is an example in the link above) and for each DataRow, create your two Labels and add them to your form. You will have to keep track of the X and Y coordinates so that you can position them properly. I could write the code out for you, but that really wouldn't help you learn. Have a go and if you get stuck, or you don't understand, please come back to me. Good luck. :)

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

            S Offline
            S Offline
            SRJ92
            wrote on last edited by
            #5

            hello, i can't get it to work and i have spent another 3 hours trying differant ways lol, can you help me ?

            H 1 Reply Last reply
            0
            • S SRJ92

              hello, i can't get it to work and i have spent another 3 hours trying differant ways lol, can you help me ?

              H Offline
              H Offline
              Henry Minute
              wrote on last edited by
              #6

              Something like:

              Label nameLabel = null;
              Label scoreLabel = null;
              int nameX = 10;
              int nameY = 10;
              readonly int nameWidth = 70; // Change this value to alter the spacing adjust scoreX accordingly, if you do
              int scoreX = 85;
              int scoreY = 10;
              int listCount = 1;
              foreach(DataRow row in dt.Rows)
              {
              nameLabel = new Label(); // Create the label
              nameLabel.Width = nameWidth; // set its width (use a variable so that you can just alter that value to change the layout)
              nameLabel.Text = row["PlayerName"].Value.ToString(); // you might need to check for null here, depends on your data.
              nameLabel.Location = new Point(nameX, nameY);
              this.Controls.Add(nameLabel)
              nameY += nameLabel.Height + 5; // add 5 for spacing. You could use a variable as for the width. The X value stays the same so that the left edges line up

              // Do the same for scoreLabel
              ........................
              ........................
              ........................
              ........................
              
              listCount++;
              if (listCount > 10) // to ensure only the 10 as per your original post.
              {
                break;
              }
              

              }

              That is roughly right but I'm doing it off the top of my head and it is very late here, so forgive any syntax errors. Good luck. :)

              Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

              S 1 Reply Last reply
              0
              • H Henry Minute

                Something like:

                Label nameLabel = null;
                Label scoreLabel = null;
                int nameX = 10;
                int nameY = 10;
                readonly int nameWidth = 70; // Change this value to alter the spacing adjust scoreX accordingly, if you do
                int scoreX = 85;
                int scoreY = 10;
                int listCount = 1;
                foreach(DataRow row in dt.Rows)
                {
                nameLabel = new Label(); // Create the label
                nameLabel.Width = nameWidth; // set its width (use a variable so that you can just alter that value to change the layout)
                nameLabel.Text = row["PlayerName"].Value.ToString(); // you might need to check for null here, depends on your data.
                nameLabel.Location = new Point(nameX, nameY);
                this.Controls.Add(nameLabel)
                nameY += nameLabel.Height + 5; // add 5 for spacing. You could use a variable as for the width. The X value stays the same so that the left edges line up

                // Do the same for scoreLabel
                ........................
                ........................
                ........................
                ........................
                
                listCount++;
                if (listCount > 10) // to ensure only the 10 as per your original post.
                {
                  break;
                }
                

                }

                That is roughly right but I'm doing it off the top of my head and it is very late here, so forgive any syntax errors. Good luck. :)

                Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                S Offline
                S Offline
                SRJ92
                wrote on last edited by
                #7

                Thank you ever so much :P

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups