Click here to Skip to main content
15,910,277 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hey guys,

i really need help on this one..

i have a database table with the following columns : [shiftDate, shiftType]

i want to display it in a datagridview wherein the values in shiftDate are the columnheaders and the cell value corresponding to that column has the value of shiftType.

so far all i know is that in datagridview you can only bind table columns as columns..

so how do i solve this?

thanks,
Posted
Updated 3-Oct-11 23:10pm
v2

1 solution

There is a limit in the number of columns you can have in a DataGridView control, so it is not advisable to put your date rows into the columns.

Also scrolling horizontally is a user interface killer.

If however you want to do this look into pivots on your data before showing.
 
Share this answer
 
Comments
Espen Harlinn 4-Oct-11 5:29am    
Good point
markypm 4-Oct-11 5:29am    
I'm only going to display the number of days in a month say if a user selected february then my column headers would contain 1-28 and if that corresponding day is in the database table then the rowcell will show the value of shiftType.
BobJanova 4-Oct-11 5:46am    
28 columns is still going to be a bad interface experience. I suggest a UI rethink first.
markypm 4-Oct-11 6:01am    
what im trying to do is a schedule management system kinda.. so you have this datagridview with all employees name listed in the first column. to set a roster a user simply has to click a cell nothing more.. so that's why i need it displayed that way. i honestly couldnt think of a better way to display such functionality. something like
Feb1 Feb2 ... Feb28
user1 S1 S1 S1
user2 S1 S2 DO
user3 S2 S1 S1

if its really that hard to do it with datagridviews.. then any suggestions are most welcome. thanks
BobJanova 4-Oct-11 7:24am    
In your question, the table you are querying doesn't mention the user name. Is that incorrect? I would expect a three column table in the database: user, date, shift.

31 columns might be ok if each one is really small, like 30px, and this table is the main purpose of the UI you're displaying. (That's still 930px used so not really suitable for a web or mobile interface, but you said WinForms.)

I recommend some kind of translator which takes the database structure version of the query and makes a cross-tab (columns depending on input data), then bind that to the grid control.

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