Help with DataGridTableStyle?

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

    #1

    Help with DataGridTableStyle?

    I have the following DataGridTableSt yle:

    DataGridTableSt yle gridTableStyle = new DataGridTableSt yle();
    gridTableStyle. MappingName = "myStyle";
    DataGridTextBox Column dgsc = new DataGridTextBox Column();
    dgsc.MappingNam e = "FirstName" ;
    dgsc.HeaderText = "First Name";
    dgsc.Width = 30;
    dgsc.TextBox.En abled = false;
    gridTableStyle. GridColumnStyle s.Add(dgsc);

    mygrid.TableSty les.Add(gridTab leStyle);
    mygrid.DataSour ce = someDataView;

    I can see in the grid for the assigned table that the firstname column
    is "FirstName" . That should match. Instead, every row from the
    DataSet shows in the grid. Shouldn't only the firstname column
    display? What am I doing wrong?

    Thanks,
    Brett

  • Brett Romero

    #2
    Re: Help with DataGridTableSt yle?

    Actually, I just needed to change this
    gridTableStyle. MappingName = "myStyle";

    to the actual table name coming from the DataSource.

    Brett

    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: Help with DataGridTableSt yle?

      Brett,

      I don't think that you need to set the MappingName property on the table
      style. The mapping name is for when you are binding to a specific type, not
      for the name of the table, I believe.

      From the documentation for the MappingName property:

      To bind the DataGrid to a strongly typed array of objects, the object type
      must contain public properties. To create a DataGridTableSt yle that displays
      the array, set the DataGridTableSt yle.MappingName property to typename where
      typename is replaced by the name of the object type. Also note that the
      MappingName property is case-sensitive; the type name must be matched
      exactly. See the MappingName property for an example.

      Hope this helps.

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

      "Brett Romero" <account@cygen. com> wrote in message
      news:1137004759 .071339.158670@ g49g2000cwa.goo glegroups.com.. .[color=blue]
      >I have the following DataGridTableSt yle:
      >
      > DataGridTableSt yle gridTableStyle = new DataGridTableSt yle();
      > gridTableStyle. MappingName = "myStyle";
      > DataGridTextBox Column dgsc = new DataGridTextBox Column();
      > dgsc.MappingNam e = "FirstName" ;
      > dgsc.HeaderText = "First Name";
      > dgsc.Width = 30;
      > dgsc.TextBox.En abled = false;
      > gridTableStyle. GridColumnStyle s.Add(dgsc);
      >
      > mygrid.TableSty les.Add(gridTab leStyle);
      > mygrid.DataSour ce = someDataView;
      >
      > I can see in the grid for the assigned table that the firstname column
      > is "FirstName" . That should match. Instead, every row from the
      > DataSet shows in the grid. Shouldn't only the firstname column
      > display? What am I doing wrong?
      >
      > Thanks,
      > Brett
      >[/color]


      Comment

      • sChar

        #4
        Re: Help with DataGridTableSt yle?

        /*You Need to Add only the required Column to a DataTable and then bind
        that to the grid. */

        dgsc.ColumnName = "FirstName" ;
        /*Then you should add this Column to the Binding table*/
        DataTable SomeDataTable = new DataTable();
        SomeDataTable.C olumns.Add(dgsc );

        /*then */

        mygrid.DataSour ce = SomeDataTable;


        HTH

        Comment

        • Peter Bromberg [C# MVP]

          #5
          RE: Help with DataGridTableSt yle?

          Brett,
          You can suppress the display of a column with (example)

          ds.Tables("Prod ucts").Columns( "QuantityPerUni t").ColumnMappi ng =
          MappingType.Hid den

          --Peter

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

          UnBlog:





          "Brett Romero" wrote:
          [color=blue]
          > I have the following DataGridTableSt yle:
          >
          > DataGridTableSt yle gridTableStyle = new DataGridTableSt yle();
          > gridTableStyle. MappingName = "myStyle";
          > DataGridTextBox Column dgsc = new DataGridTextBox Column();
          > dgsc.MappingNam e = "FirstName" ;
          > dgsc.HeaderText = "First Name";
          > dgsc.Width = 30;
          > dgsc.TextBox.En abled = false;
          > gridTableStyle. GridColumnStyle s.Add(dgsc);
          >
          > mygrid.TableSty les.Add(gridTab leStyle);
          > mygrid.DataSour ce = someDataView;
          >
          > I can see in the grid for the assigned table that the firstname column
          > is "FirstName" . That should match. Instead, every row from the
          > DataSet shows in the grid. Shouldn't only the firstname column
          > display? What am I doing wrong?
          >
          > Thanks,
          > Brett
          >
          >[/color]

          Comment

          Working...