DataGrid DataSource, DataGridTableStyle, and Strongly Typed Collection

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.

LVL 7
brdrokAsked:
Who is Participating?
 
vo1dCommented:
you will also have to setup the GridColumnStyles of your tablestyle object.initialize for every column you wanna display a columnstyle.
0
 
brdrokAuthor Commented:
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
 
vo1dCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.