Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Do detail grids show up even if you don't have detail data for a row?

Sort Posts: Previous Next
  •  05-16-2008, 9:21 AM Post no. 12331

    Do detail grids show up even if you don't have detail data for a row?

    I'm evaluating the Grid control for .NET.  I'm filling in the data manually.  My requirement is to display is to display a 2 level hiarchy with a conditional third.  I understand that a detail grid can be used.  The 2nd level down can sometimes have a third level but I don't want to display that level (3rd) for a particular detail row (2nd level) if that row doesn't have any detail data (for this conditional 3rd level) not even headers for that 3rd level

     A
        A1
        A2 
            A2.1   
        A3
        A4

    B
        B1
            B1.1
            B1.2
        B2
        B3
            B3.1

    Also, a question on the WPF grid.  Are the concepts for the WPF grid the same as the .NET Grid with detail grids for creating levels?

     

    Thank

    Bernie

  •  05-16-2008, 4:13 PM Post no. 12344 in reply to 12331

    Re: Do detail grids show up even if you don't have detail data for a row?

    You can set the Visibility to false on the Detail grid and the ShowPlusMinus to Never on the Parent DataRow.

    Here is a code example:

    private void Form1_Load( object sender, EventArgs e )
    {
      grid.BeginInit();           

      grid.Columns.Add( new Column( "FirstName", typeof( string ) ) );
      grid.Columns.Add( new Column( "LastName", typeof( string ) ) );
      grid.Columns.Add( new Column( "FamilyID", typeof( int ) ) );
      grid.Columns.Add( new Column( "Occupation", typeof( string ) ) );

      Xceed.Grid.DataRow row1 = grid.DataRows.AddNew();
      row1.Cells[ "FirstName" ].Value = "Peter";
      row1.Cells[ "LastName" ].Value = "Griffin";
      row1.Cells[ "FamilyID" ].Value = 1;
      row1.Cells[ "Occupation" ].Value = "Fisherman";
      row1.EndEdit();

      Xceed.Grid.DataRow row2 = grid.DataRows.AddNew();
      row2.Cells[ "FirstName" ].Value = "Homer";
      row2.Cells[ "LastName" ].Value = "Simpson";
      row2.Cells[ "FamilyID" ].Value = 2;
      row2.Cells[ "Occupation" ].Value = "Nuclear Technician";
      row2.EndEdit();

      DetailGrid detail = new DetailGrid();

      detail.HeaderRows.Add( new ColumnManagerRow() );

      detail.Columns.Add( new Column( "FirstName", typeof( string ) ) );
      detail.Columns.Add( new Column( "Relationship", typeof( string ) ) );
      detail.Columns.Add( new Column( "FamilyID", typeof( int ) ) );

      grid.DetailGridTemplates.Add( detail );
      grid.InitializingDetailGrid += new InitializingDetailGridEventHandler( this.init_details );

      grid.EndInit();

      DetailGrid childDetail = new DetailGrid();

      childDetail.HeaderRows.Add( new ColumnManagerRow() );
      childDetail.Columns.Add( new Column( "Episode", typeof( string ) ) );
      childDetail.Columns.Add( new Column( "Date Aired", typeof( DateTime ) ) );

      detail.DetailGridTemplates.Add( childDetail );
      detail.InitializingDetailGrid += new InitializingDetailGridEventHandler( detail_InitializingDetailGrid );
      grid.UpdateDetailGrids();

    }

    void detail_InitializingDetailGrid( object sender, InitializingDetailGridEventArgs e )
    {
      string value = e.Grid.ParentDataRow.Cells[ "FirstName" ].Value.ToString();
      if( value == "Meg" || value =="Lisa" )
      {
        e.Grid.Visible = false;
        e.Grid.ParentDataRow.ShowPlusMinus = ShowPlusMinus.Never;
      }
      else
      {
        Xceed.Grid.DataRow row1 = e.Grid.DataRows.AddNew();
        row1.Cells[ "Episode" ].Value = "Episode 1";
        row1.Cells[ "Date Aired" ].Value = new DateTime( 2003, 12, 15 );
        row1.EndEdit();
      }
    }

    private void init_details( object sender, InitializingDetailGridEventArgs e )
    {
      switch( ( int )e.Grid.ParentDataRow.Cells[ "FamilyID" ].Value )
      {
        case 1:
          {
            Xceed.Grid.DataRow row1 = e.Grid.DataRows.AddNew();
            row1.Cells[ "FirstName" ].Value = "Lois";
            row1.Cells[ "Relationship" ].Value = "Wife";
            row1.Cells[ "FamilyID" ].Value = 1;
            row1.EndEdit();

            Xceed.Grid.DataRow row2 = e.Grid.DataRows.AddNew();
            row2.Cells[ "FirstName" ].Value = "Meg";
            row2.Cells[ "Relationship" ].Value = "Daughter";
            row2.Cells[ "FamilyID" ].Value = 1;
            row2.EndEdit();

            Xceed.Grid.DataRow row3 = e.Grid.DataRows.AddNew();
            row3.Cells[ "FirstName" ].Value = "Chris";
            row3.Cells[ "Relationship" ].Value = "Son";
            row3.Cells[ "FamilyID" ].Value = 1;
            row3.EndEdit();

            Xceed.Grid.DataRow row4 = e.Grid.DataRows.AddNew();
            row4.Cells[ "FirstName" ].Value = "Stewie";
            row4.Cells[ "Relationship" ].Value = "Son";
            row4.Cells[ "FamilyID" ].Value = 1;
            row4.EndEdit();

            Xceed.Grid.DataRow row5 = e.Grid.DataRows.AddNew();
            row5.Cells[ "FirstName" ].Value = "Brian";
            row5.Cells[ "Relationship" ].Value = "Dog";
            row5.Cells[ "FamilyID" ].Value = 1;
            row5.EndEdit();

            break;
          }
        case 2:
          {
            Xceed.Grid.DataRow row1 = e.Grid.DataRows.AddNew();
            row1.Cells[ "FirstName" ].Value = "Marge";
            row1.Cells[ "Relationship" ].Value = "Wife";
            row1.Cells[ "FamilyID" ].Value = 2;
            row1.EndEdit();

            Xceed.Grid.DataRow row2 = e.Grid.DataRows.AddNew();
            row2.Cells[ "FirstName" ].Value = "Bart";
            row2.Cells[ "Relationship" ].Value = "Son";
            row2.Cells[ "FamilyID" ].Value = 2;
            row2.EndEdit();

            Xceed.Grid.DataRow row3 = e.Grid.DataRows.AddNew();
            row3.Cells[ "FirstName" ].Value = "Lisa";
            row3.Cells[ "Relationship" ].Value = "Daughter";
            row3.Cells[ "FamilyID" ].Value = 2;
            row3.EndEdit();

            Xceed.Grid.DataRow row4 = e.Grid.DataRows.AddNew();
            row4.Cells[ "FirstName" ].Value = "Maggie";
            row4.Cells[ "Relationship" ].Value = "Daughter";
            row4.Cells[ "FamilyID" ].Value = 2;
            row4.EndEdit();

            break;
          }
      }
    }


    Charles Bérubé-Rémillard
    Technical Support
    Xceed Software Inc.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.