Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Customizing Non-Databound DataGridView Rows/Cells from DataTable/DataSet (Imitating a Calendar..sorta)

$
0
0

I've gotten a few pieces of this working, I'm not sure about an approach to the rest.  I'm somewhat mimicking a calendar control, I've got a DGV control that generates time-stamps along the side in the row HeaderCell values.  It's not databound so that I have the power to do the rows like this.

My ideal output will be something like this (the only code on this is the timestamps, just a dummy grid with dummy text entries)

There's appointments stored in the database, for instance Frank had a meeting with the ScheduledStartTime saved as 9 AM. 

The fields related to this are "Appointment" which held the value "meeting" and the ScheduledStartTime which was the 9 AM.

That customized grid class auto-generates the columns for the 24 hours worth of time stamps as seen above.

I've got a piece of code tied to a databound DGV class, that goes through the database and puts names into the column headers like so

code snippet that does the names:

public void tryIt()
        {
            demo01.Tables.Add("test");
            List<string> names = new List<string>();
            foreach (DataRow row in demo01.Tables["task"].Rows)
            {
                var name= row["NameField"].ToString();
                if (!names.Contains(name))
                {
                    names.Add(NameField.ToString());
                    demo01.Tables["test"].Columns.Add(NameField);
                    this.DataSource = demo01.Tables["test"];
                }
            }
        }
I'm having trouble getting the two tied together into the same control.  Right now this is my form.  I'm trying to merge the grids shown below

I can't add the databinding to the one that has the time stamps or they either throw errors or cancel each other out and vice versa.

Right now the only thing I can think, call the DataTable, and find a way to iterate through it to place the Appointments in the cells where the HeaderCell value matches the StartTime field, and place it under the relevant Name column on the row with that time.  It's hard to explain and so far harder to code.  If anyone is still following and cares to offer a second opinion or better approach I'd be most appreciative.

Things that have occured to me but haven't worked yet:

1) iterate the datatable, add the rows (or columns, not sure which will work or work best) to the "calendar" DGV one at a time

2) Add the columns to the "calendar" one at a time and put values in one cell at a time (the headercell value approach)

3) hulk out, smash the computer, raid the coffee, and walk away.

Not big on #3 but haven't ruled it out. 


May the fleas of a thousand camels feast happily on the lower regions of your enemies. And may their arms be too short to scratch!


Viewing all articles
Browse latest Browse all 2535

Trending Articles