How to display data on a Windows form (without using a datagrid)?..

P

Peter Demeyer

I want to display data from a database as labels on a form without using a datagrid.
My problem is that I can't make the labels at design time because the amount of data is variable.
It should look a bit like this:

John 1/8/1970 Edit Remove
Peter 8/2/1972 Edit Remove
etc.

Creating a data source and dragging columns to the form doesn't seem to be the right solution for me because my data source should be something like "SELECT name, birthdate FROM people WHERE postcode=<selected value in a combobox on this form>"

The only obvious way I can see is to write code that creates labels, positions them and possibly make the form bigger if it doesn't all fit, but this seems like a lot of work and this seems such a common thing that I'd be surprised that there isn't a control (like a table) for this or something.
Easy enough on a web page I think, just add rows to a table, but this is a Windows form.
I don't like a datagrid so much because I don't think I can put buttons or labels like Edit (or a picture of a rubbish bin) in a datagrid.

Thanks for any help,

Peter
 
G

Guest

If you're using Whidbey (2.0), I'd suggest taking a peek at DataGridView,
which is a more advanced grid that addresses the problems you had with
DataGrid. If you don't want to do that, you could use TableLayoutPanel
(again only in 2.0).

If you're using 1.0 or 1.1, I'm afraid you're right: you'd either need to
write your own control or find a 3rd party control that does this for you.
-Scott
 
S

Stoitcho Goutsev \(100\)

Peter,

My advice is not go with too many controls. If you do, your next question will be "why my application is so slow".
There is always a reasonable amount of controls that can be put on a form and the number is not that big. How-to-speed-up-my-application-that-has-hundreds-controls-on-the-form questions has been asked many times in the newsgroups. So my advice is use some kind of a grid control or draw your data, but don't use controls for each small piece of information there. If you need editing for example use one control and move it over the data that needs to be edited; don't create hundreds of comboboxes for instance.

--
HTH
Stoitcho Goutsev (100)
I want to display data from a database as labels on a form without using a datagrid.
My problem is that I can't make the labels at design time because the amount of data is variable.
It should look a bit like this:

John 1/8/1970 Edit Remove
Peter 8/2/1972 Edit Remove
etc.

Creating a data source and dragging columns to the form doesn't seem to be the right solution for me because my data source should be something like "SELECT name, birthdate FROM people WHERE postcode=<selected value in a combobox on this form>"

The only obvious way I can see is to write code that creates labels, positions them and possibly make the form bigger if it doesn't all fit, but this seems like a lot of work and this seems such a common thing that I'd be surprised that there isn't a control (like a table) for this or something.
Easy enough on a web page I think, just add rows to a table, but this is a Windows form.
I don't like a datagrid so much because I don't think I can put buttons or labels like Edit (or a picture of a rubbish bin) in a datagrid.

Thanks for any help,

Peter
 
P

Peter Demeyer

Thank you both for your advise.
I will have a look at the DataGridView then, even though it doesn't look so nice and it doesn't look like I can make "Edit" and "Remove" buttons next to each record.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top