Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All

I Want Show Selected Top 10 Record In Label Control in csharp

For Example Record Fields Are :

Name Family Phone Number

How Do Show Above Records In 10 Rows With Label Like Below :

Name1  Family1  Phone1 Number1

Name2  Family2  Phone2 Number2

...

Name10  Family10  Phone10 Number10


Attention :
Above Record Show In Label and NOt DataGridView

Thanks A Lot
Posted
Comments
Sergey Alexandrovich Kryukov 4-May-12 19:20pm    
Reason for my vote of 1
Baseless question.

If you need some UI properties, don't tell us what to use and what not, describe your requirements.

In this case, you require something what Label control is not designed for. Does it mean the problem is not solvable? Of cause it is solvable, from the standpoint of pure UI requirements. But to make is solvable, you should not impose unreasonable limitations.

You can give either question or a solution, not both.

Also, application type or UI library is not specified. Tag it: WPF? Forms? Silverlight? ASP.NET? What?

--SA
Shahin Khorshidnia 6-May-12 2:59am    
Hello. SA, I've already read your comment. Although I've answered the question, but I must own that you usually notice cases which I can't pay attention. Yes there are more suitable controls than Label for this case. Thank you for notification.

1 solution

Hello,


for example you want to show person entity.

C#
var people = context.People.Select(p=>p);

people = (people.Count()>=10)? people.Top(10): people.Top(people.Count());

foreach(Person p in people)
{
   Label name = new Label();
   name.Text = p.Name;
   Label family = new Label();
   family.Text = p.Family;
   //...

   this.Controls.Add(name);
   this.Controls.Add(family);
   //...
}


context is your whole database; if you don't know how to have it then forget it and use the collection that is storing the Person entity insted of context.People
For example you have a List<Person> PeopleList;
C#
var people = (PeopleList.Count()>=10)? PeopleList.Top(10): PeopleList.Top(PeopleList.Count());
//...


Maybe you need to set Left and Top of all Labels.


I've written the code by hand and I haven't tested it but the base is correct.
 
Share this answer
 
v6
Comments
VJ Reddy 5-May-12 23:20pm    
Good answer. 5!
Shahin Khorshidnia 6-May-12 2:45am    
Thank you very much VJ.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900