Home Forums WinForms controls Xceed Grid for WinForms Do detail grids show up even if you don’t have detail data for a row? Reply To: Do detail grids show up even if you don’t have detail data for a row?

Xceed Support
Member
Post count: 5658

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;
      }
  }
}

Imported from legacy forums. Posted by CharlesB (had 1174 views)