Visual Studio.Net 2003 and DataGrids

This is a discussion on Visual Studio.Net 2003 and DataGrids within the Windows Programming forums, part of the Platform Specific Boards category; Hi All, I am trying to create a DataGrid for a weekly employee schedule. While the columns would be statically ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    16

    Visual Studio.Net 2003 and DataGrids

    Hi All,

    I am trying to create a DataGrid for a weekly employee schedule. While the columns would be statically set to the days of the week, the rows should show the employees and their scheduled times on each day. I am using Visual C++ Forms to create the DataGrid.

    The database containing the employees is just a simple file that is loaded into a struct on start-up of the program.

    I have been studying the msdn files to find out how to set up the DataGrid, bind it to a data source and load the grid with the necessay info. I have also checked numerous tutorials on how to do this. Most of the tutorials are domain specific such as, using sql data bases or extracting xml file info. I am finding the various information a bit discombobulated, thus hard to pinpoint what I really need to do.

    So far, I have set up a class called ScheduleTable to deal with initializing the table schema. At this point, it is supposed to add a couple of columns to the table. But, I can't figure out how to make the table initialize to this schema.

    Once I have figured out how to initialize the table, I need to figure out how to load the data from the employee struct. I'm sure that this task can be accomplished through the DataBindings properties. But, since my data comes from a struct, I am unsure how the struct will relate to the DataBindings properties.

    Could anyone help me sift through the information overload so that I can first, initialize the schema, and second, load the table from my struct.

    If you need anymore info to help me, just ask. I have not provided the source code since it compiles and my main problem lies in the linking of the schema to the DataGrid. For this problem, I have no code available.

    Thanks to all who have tips or hints that I could use.

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    16

    Found the answer!

    Now that I've finished my exam yesterday I am ready to get back into this with a fresh mind. So I was able to find a tutorial that showed me how to do it. There are no data bindings involved, or anything remotely complicated about it.

    In fact its kind of embarrassing that it is so simple. Instead of creating a new class I moved the code into the Forms1.h file and added a load button with the following code.

    Code:
    private: System::Void loadTable_Click(System::Object *  sender, System::EventArgs *  e)
    		 {
    			DataSet __gc *dsPersons = __gc new DataSet(S"Employees Records");
    			DataTable __gc *dtPersons = __gc new DataTable;
    
    			DataColumn __gc *dcCategory = __gc new DataColumn;
    		 
    			dcCategory->ColumnName = S"Name";
    			dcCategory->DataType = System::Type::GetType(S"System.String");
    			dtPersons->Columns->Add(dcCategory);
    			dcCategory = new DataColumn(S"Monday", System::Type::GetType(S"System.String"));
    			dtPersons->Columns->Add(dcCategory);
    			dcCategory = new DataColumn(S"Tuesday");
    			dcCategory->DataType = System::Type::GetType(S"System.String");
    			dtPersons->Columns->Add(dcCategory);
    			dcCategory = new DataColumn(S"Wednesday", System::Type::GetType(S"System.String"));
    			dtPersons->Columns->Add(dcCategory);
    			dcCategory = new DataColumn(S"Thursday", System::Type::GetType(S"System.String"));
    			dtPersons->Columns->Add(dcCategory);
    			dcCategory = new DataColumn(S"Friday", System::Type::GetType(S"System.String"));
    			dtPersons->Columns->Add(dcCategory);
    			dcCategory = new DataColumn(S"Saturday", System::Type::GetType(S"System.String"));
    			dtPersons->Columns->Add(dcCategory);
    			dsPersons->Tables->Add(dtPersons);
    		 
    			DataRow __gc *drPersons;
    				 
    			drPersons = dtPersons->NewRow();
    			drPersons->Item[S"Name"] = S"John Smith";
    			drPersons->Item[S"Monday"] = S"8:00 to 4:00";
    			drPersons->Item[S"Tuesday"] = S"OFF";
    			dtPersons->Rows->Add(drPersons);
    
    			drPersons = dtPersons->NewRow();
    			drPersons->Item[S"Name"] = S"Jill Smith";
    			drPersons->Item[S"Monday"] = S"9:00 to 5:00";
    			drPersons->Item[S"Tuesday"] = S"9:00 to 5:00";
    			dtPersons->Rows->Add(drPersons);
    
    			this->dataGrid1->DataSource = dsPersons;
    			this->dataGrid1->DataMember = S"Table1";
    
    		 }
    Now all I need to do is add the row information from my struct instead off hardcoding the values in.

    For a full tutorial check out: http://www.functionx.com/vcnet/colle.../datatable.htm

    These tutorials are very easy to understand for many other topics.

    Have a good one all.
    Last edited by snowblind37; 07-01-2004 at 09:39 AM. Reason: code tags are wrong

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21