How to debug DataGridTableStyle?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brett Romero

    #1

    How to debug DataGridTableStyle?

    When I create this table and add it to my DataGrid (framework v1.1),
    the TableStyle works fine:

    DataTable dt = new DataTable();
    DataColumn dc = new DataColumn("Are aCode");
    DataColumn dctwo = new DataColumn("Tes t");
    dt.Columns.Add( dc);
    dt.Columns.Add( dctwo);

    I have the style set to only show AreaCode. However, when I use a
    table from the database, every column displays. AreaCode is a column
    in this table, which means I should only see AreaCode in the grid.

    I've looked at the grid properties in the debugger and see the
    tablestyle AreaCode column is there. I also see in the DataTable a
    column named AreaCode. What else do I need to look for to figure it
    out?

    Thanks,
    Brett

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: How to debug DataGridTableSt yle?

    Brett,

    The problem here isn't the grid and how it is set up, but rather, the
    table itself. You say when you get a database from the table, this happens.
    Well, are you selecting all of the fields, or some of them? If it is all of
    them, then that's what you are going to see in the grid.

    You need to cut down your selection so that you only select the fields
    that you want.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Brett Romero" <account@cygen. com> wrote in message
    news:1138062101 .898289.280720@ f14g2000cwb.goo glegroups.com.. .[color=blue]
    > When I create this table and add it to my DataGrid (framework v1.1),
    > the TableStyle works fine:
    >
    > DataTable dt = new DataTable();
    > DataColumn dc = new DataColumn("Are aCode");
    > DataColumn dctwo = new DataColumn("Tes t");
    > dt.Columns.Add( dc);
    > dt.Columns.Add( dctwo);
    >
    > I have the style set to only show AreaCode. However, when I use a
    > table from the database, every column displays. AreaCode is a column
    > in this table, which means I should only see AreaCode in the grid.
    >
    > I've looked at the grid properties in the debugger and see the
    > tablestyle AreaCode column is there. I also see in the DataTable a
    > column named AreaCode. What else do I need to look for to figure it
    > out?
    >
    > Thanks,
    > Brett
    >[/color]


    Comment

    • Brett Romero

      #3
      Re: How to debug DataGridTableSt yle?

      That's not completely correct Nick. I'm doing this with a custom
      datagrid. On the regular winform datagrid, I use a tablestyle to
      dispay 8 of 10 fields returned in the set from a database.

      This has to be something specific to my custom grid. It's puzzling
      though b/c the little two column table I created works with the custom
      grid. I can display 1 of 2 columns. How is that any different than
      what comes from the database and is put into a dataset, which I then
      reference?

      It has more column than I want displayed. However, the tablestyle
      takes care of that. Just not yet because I'm missing something in my
      custom grid's logic, which I'm trying to pin point.

      Thanks,
      Brett

      Comment

      • Peter Bromberg [C# MVP]

        #4
        RE: How to debug DataGridTableSt yle?

        Brett,
        Try using MappingType.Hid den to suppress display of columns you don't want
        displayed, e.g.:
        ds.Tables[2].Columns["DeviceTypeMode lID"].ColumnMapping = MappingType.Hid den;

        Peter
        --
        Co-founder, Eggheadcafe.com developer portal:

        UnBlog:





        "Brett Romero" wrote:
        [color=blue]
        > When I create this table and add it to my DataGrid (framework v1.1),
        > the TableStyle works fine:
        >
        > DataTable dt = new DataTable();
        > DataColumn dc = new DataColumn("Are aCode");
        > DataColumn dctwo = new DataColumn("Tes t");
        > dt.Columns.Add( dc);
        > dt.Columns.Add( dctwo);
        >
        > I have the style set to only show AreaCode. However, when I use a
        > table from the database, every column displays. AreaCode is a column
        > in this table, which means I should only see AreaCode in the grid.
        >
        > I've looked at the grid properties in the debugger and see the
        > tablestyle AreaCode column is there. I also see in the DataTable a
        > column named AreaCode. What else do I need to look for to figure it
        > out?
        >
        > Thanks,
        > Brett
        >
        >[/color]

        Comment

        • Nicholas Paldino [.NET/C# MVP]

          #5
          Re: How to debug DataGridTableSt yle?

          Brett,

          Well, post a code sample and let's see for ourselves.

          DataSets that are populated from a DataAdapter tend to be no different
          than anything populated by hand. However, that doesn't mean that when you
          populate something by hand, you might miss what a DataAdapter might normally
          set.

          --
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard. caspershouse.co m

          "Brett Romero" <account@cygen. com> wrote in message
          news:1138080665 .685132.126230@ g14g2000cwa.goo glegroups.com.. .[color=blue]
          > That's not completely correct Nick. I'm doing this with a custom
          > datagrid. On the regular winform datagrid, I use a tablestyle to
          > dispay 8 of 10 fields returned in the set from a database.
          >
          > This has to be something specific to my custom grid. It's puzzling
          > though b/c the little two column table I created works with the custom
          > grid. I can display 1 of 2 columns. How is that any different than
          > what comes from the database and is put into a dataset, which I then
          > reference?
          >
          > It has more column than I want displayed. However, the tablestyle
          > takes care of that. Just not yet because I'm missing something in my
          > custom grid's logic, which I'm trying to pin point.
          >
          > Thanks,
          > Brett
          >[/color]


          Comment

          • Brett Romero

            #6
            Re: How to debug DataGridTableSt yle?

            I use the MS DataAccess block, which uses an sqlhelper. It returns a
            data reader, which I loop through to create a dataset. So there isn't
            a data adapter involved in the code. What else can I post?

            Thanks,
            Brett

            Comment

            • Bart Mermuys

              #7
              Re: How to debug DataGridTableSt yle?

              Hi,

              "Brett Romero" <account@cygen. com> wrote in message
              news:1138062101 .898289.280720@ f14g2000cwb.goo glegroups.com.. .[color=blue]
              > When I create this table and add it to my DataGrid (framework v1.1),
              > the TableStyle works fine:
              >
              > DataTable dt = new DataTable();
              > DataColumn dc = new DataColumn("Are aCode");
              > DataColumn dctwo = new DataColumn("Tes t");
              > dt.Columns.Add( dc);
              > dt.Columns.Add( dctwo);
              >
              > I have the style set to only show AreaCode. However, when I use a
              > table from the database, every column displays. AreaCode is a column
              > in this table, which means I should only see AreaCode in the grid.
              >
              > I've looked at the grid properties in the debugger and see the
              > tablestyle AreaCode column is there. I also see in the DataTable a
              > column named AreaCode. What else do I need to look for to figure it
              > out?[/color]

              The first thing to check when DGColumnStyle's don't seem to work is whether
              you have set the correct MappingName for the DGTableStyle,
              DGTableStyle.Ma ppingName must be the same as the bound DataTable.Table Name.

              DataGridTableSt yle dgts = new DataGridTableSt yle();
              dgts.MappingNam e = someDataTable.T ableName; // !!

              .... add DataGridColumnS tyles ...

              someDataGrid.Ta bleStyles.Add( dgts );
              someDataGrid.Da taSource = someDataTable;


              HTH,
              Greetings
              [color=blue]
              >
              > Thanks,
              > Brett
              >[/color]


              Comment

              • Nicholas Paldino [.NET/C# MVP]

                #8
                Re: How to debug DataGridTableSt yle?

                Well, SOME code would have been helpful, but I digress.

                Why are you populating the data set yourself? You should be able to
                tell the data access block to populate the data set for you, using a data
                adapter.


                --
                - Nicholas Paldino [.NET/C# MVP]
                - mvp@spam.guard. caspershouse.co m

                "Brett Romero" <account@cygen. com> wrote in message
                news:1138116486 .963793.62440@g 44g2000cwa.goog legroups.com...[color=blue]
                >I use the MS DataAccess block, which uses an sqlhelper. It returns a
                > data reader, which I loop through to create a dataset. So there isn't
                > a data adapter involved in the code. What else can I post?
                >
                > Thanks,
                > Brett
                >[/color]


                Comment

                • Brett Romero

                  #9
                  Re: How to debug DataGridTableSt yle?

                  Bart, you absolutely got it! That was the disconnect. The table name
                  and tablestyle mappingname were different.

                  I'd like to override DataSource() in my custom grid so I can look for
                  the table name. This way I can be sure the mapping and table names are
                  always the same. However, the datasource may take a dataset, datatable
                  or dataview. I'd need to know how to get at the table to retreive the
                  table name. Do I need to setup switch statements in the DataSource()
                  method, look for each type and extract the table name?

                  Thanks,
                  Brett

                  Comment

                  • Bart Mermuys

                    #10
                    Re: How to debug DataGridTableSt yle?

                    Hi,

                    "Brett Romero" <account@cygen. com> wrote in message
                    news:1138122744 .055110.140240@ g44g2000cwa.goo glegroups.com.. .[color=blue]
                    > Bart, you absolutely got it! That was the disconnect. The table name
                    > and tablestyle mappingname were different.
                    >
                    > I'd like to override DataSource() in my custom grid so I can look for
                    > the table name. This way I can be sure the mapping and table names are
                    > always the same. However, the datasource may take a dataset, datatable
                    > or dataview. I'd need to know how to get at the table to retreive the
                    > table name. Do I need to setup switch statements in the DataSource()
                    > method, look for each type and extract the table name?[/color]

                    A little advanced, but you could use a CurrencyManager for this.
                    CurrencyManager .List points to the list that is actually bound, that list
                    will implement ITypedList if it has a name otherwise the type-name must be
                    used, example:

                    // DataMember can be an empty string (eg. when bound to DataTable)
                    CurrencyManager cm = (CurrencyManage r)
                    BindingContext[DataSource, DataMember];

                    ITypedList typedList = cm.List as ITypedList;
                    string listName = "";
                    if ( typedList!=null )
                    listName = typedList.GetLi stName(null);
                    else
                    listName = cm.List.GetType ().Name;

                    That should work for almost anything (DataSet, DataTable, DataView, custom
                    lists, arrays ).

                    Offcourse you could also use a switch but then it's less generic.

                    HTH,
                    Greetings
                    [color=blue]
                    >
                    > Thanks,
                    > Brett
                    >[/color]


                    Comment

                    Working...