DataGrid DataSource, DataGridTableStyle, and Strongly Typed Collection

Posted on 2006-05-26
Last Modified: 2008-02-20

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.

Question by:brdrok
    LVL 11

    Accepted Solution

    you will also have to setup the GridColumnStyles of your tablestyle object.initialize for every column you wanna display a columnstyle.
    LVL 7

    Author Comment

    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

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

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

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

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

                //add tablestyle to datagrid
                myGrid.Width = curPage.Width;
                myGrid.Height = curPage.Height;

                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;
          //myGrid.DataSource = attCol;
          //myGrid.SetDataBinding(attCol, "InOutTrackerBL.AttendanceCollection");
          //myGrid.DataSource = ((InOutTrackerBL.Division)  curPage.Tag).GetAttendanceCol(new DateTime(2006, 4, 20));            
    LVL 11

    Expert Comment

    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?

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    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…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now