Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > BOOK: Beginning Visual C# 2005
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Visual C# 2005
This is the forum to discuss the Wrox book Beginning Visual C# 2005 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, Eric White; ISBN: 9780764578472
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 26th, 2008, 12:20 PM
Registered User
 
Join Date: Nov 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default dynmanic labels

hi,
I'm new here and because I didn't found the awnser in this book and not in course, will I ask it here, I hope I'll get a solution on my problem.

this is the situation:

I wanna create a program that is able to create dynamically by counting results from a SQL-query(that phase is easy I know how to do it), but thereafter, I want that the solution automatically creates the labels,
like :

label1 label2 label3
label4 label5 label6

and that on a form :s

I hope it is possible :s

Reply With Quote
  #2 (permalink)  
Old November 26th, 2008, 01:00 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Actually creating the labels isn't really that difficult. Assume that you have a placeholder on your form named phControls your code would look something like this:

(Assume dt is a DataTable object)
for(int i = 0; i < dt.Rows.Count();i++)
{
   Label lbl = new Label();
   lbl.ID = "lbl" + Convert.ToString(i);
   lbl.Text = Convert.ToString(dt.Rows[i]["SomeColumn"]);
   phControls.Controls.Add(lbl);
}

This is pretty simple, however, if you run the code as is you will only see the last label added to the placeholder because each label in the code above would be placed in the exact same position within the placeholder, effectively stacking subsequent labels on top of one another.

To over come this assign values to the Top and Left properties of the label so:
lbl.Top = 10;
lbl.Left = 15;

Obviously you will need to change these values on each iteration of the loop but this should give you a good starting point.

hth.
-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #3 (permalink)  
Old November 27th, 2008, 04:26 AM
Registered User
 
Join Date: Nov 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thx for the post,
I will try it as soon as I can :)

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vertical Labels bfoley CSS Cascading Style Sheets 2 November 26th, 2007 02:06 PM
Labels on form sweet4511 VB How-To 2 July 20th, 2005 11:46 AM
Labels in Access taraj Access 2 May 16th, 2005 01:35 PM
Labels slgknjn Beginning VB 6 9 February 25th, 2005 04:12 PM
Labels in DataLists shmacgregor ASP.NET 1.0 and 1.1 Basics 4 April 2nd, 2004 03:28 AM



All times are GMT -4. The time now is 08:56 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.