Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

DataGrid DataSource, DataGridTableStyle, and Strongly Typed Collection

Posted on 2006-05-26
3
Medium Priority
?
481 Views
Last Modified: 2008-02-20
Hello,

I have a strongly typed collection (a class that inherits from CollectionBase) that I would like to assign to the datagrid's datasource.  I also created a DataGridTableStyle object and assigned it to the datagrid as well.  However, my DataGridTableStyle is not being used and instead dispalys all the columns as opposed to the columns as specified via the DataGridTableStyle.

Hope I made sense...if not...please feel free to ask for more details.

0
Comment
Question by:brdrok
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
vo1d earned 1400 total points
ID: 16768719
you will also have to setup the GridColumnStyles of your tablestyle object.initialize for every column you wanna display a columnstyle.
0
 
LVL 7

Author Comment

by:brdrok
ID: 16768887
thanks for the reply.  I probably should have mentioned that in my original post but I already did that too.  Below is what I got so far.

private void GenerateAttendanceGrid(TabPage curPage, DateTime selDate)
{
      DataTable dt = null;
      DataGridTableStyle ts = new DataGridTableStyle();

      DataGrid myGrid;

      if(curPage.Controls.Count == 0)
      {
            myGrid = new DataGrid();

            //create column(s)
            DataGridColumnStyle cEmpName = new DataGridTextBoxColumn();
            cEmpName.MappingName = "FullEmployeeName";
            cEmpName.HeaderText = "Employee";
            cEmpName.Width = 100;
            cEmpName.ReadOnly = true;
                  
            //add column to table style
            ts.GridColumnStyles.Add(cEmpName);

            DataGridColumnStyle cIsIn = new DataGridBoolColumn();
            cIsIn.MappingName = "IsIn";
            cIsIn.HeaderText = "Is In";
            cIsIn.Width = 50;
            ts.GridColumnStyles.Add(cIsIn);

            DataGridColumnStyle cIsLate = new DataGridBoolColumn();
            cIsLate.MappingName = "IsLate";
            cIsLate.HeaderText = "Late";
            cIsLate.Width = 50;
            ts.GridColumnStyles.Add(cIsLate);

            DataGridColumnStyle cOutEarly = new DataGridBoolColumn();
            cOutEarly.MappingName = "IsOutEarly";
            cOutEarly.HeaderText = "Out Early";
            cOutEarly.Width = 50;
            ts.GridColumnStyles.Add(cOutEarly);

            DataGridColumnStyle cComment = new DataGridTextBoxColumn();
            cComment.MappingName = "Comment";
            cComment.HeaderText = "Comment";
            cComment.Width = 150;
            //add column to table style
            ts.GridColumnStyles.Add(cComment);

            //add tablestyle to datagrid
            myGrid.TableStyles.Add(ts);
            myGrid.Width = curPage.Width;
            myGrid.Height = curPage.Height;

            curPage.Controls.Add(myGrid);
      }
      else
      {
            myGrid = (DataGrid) curPage.Controls[0];
      }

      InOutTrackerBL.AttendanceCollection attCol = ((InOutTrackerBL.Division) curPage.Tag).GetAttendanceCol(selDate);

      ts.MappingName = attCol.ToString();

      //dt = this.DataTableWrapper(attCol);
      //myGrid.DataSource = dt;

      myGrid.DataSource = attCol;
                  
      //TODO: FIND OUT HOW TO MANIPULATE COLUMNS WITH STRONGLY TYPEd COLLECTION
      //myGrid.DataSource = attCol;
      //myGrid.SetDataBinding(attCol, "InOutTrackerBL.AttendanceCollection");
      //myGrid.DataSource = ((InOutTrackerBL.Division)  curPage.Tag).GetAttendanceCol(new DateTime(2006, 4, 20));            
}
0
 
LVL 11

Expert Comment

by:vo1d
ID: 16769558
how could your collection be typesave if you store different datatypes in it?
you setup soem string columns and some boolean columns, this is not typesave until you store false and true as strings in your collection.
of what type is your collection?
how does your collection looks like?
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Loops Section Overview
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question