locked
why is that datagridview hiding ... RRS feed

  • Question

  • hi

    i want to use datagridview front of panel.

     

    but if i use that panel, that datagridview is hidding because of that panel.

     

    thank you~

    Wednesday, June 29, 2011 9:14 PM

Answers

  • Hello LeeHyungGeun ,

     

    try this example of code, you can add all methods in the load evento in your form 1

     

      DataGridView dataGridView1 = new DataGridView();
    
      private void Form1_Load(object sender, EventArgs e)
      {
       SetupDataGridView();
       PopulateDataGridView();
      }
    
      private void SetupDataGridView()
      {
    
       this.panel1.Controls.Add(dataGridView1);
    
       dataGridView1.ColumnCount = 5;
    
       dataGridView1.Columns[0].Name = "Release Date";
       dataGridView1.Columns[1].Name = "Track";
       dataGridView1.Columns[2].Name = "Title";
       dataGridView1.Columns[3].Name = "Artist";
       dataGridView1.Columns[4].Name = "Album";
      }
    
      private void PopulateDataGridView()
      {
       string[] row0 = { "11/22/1968", "29", "Revolution 9", "Beatles", "The Beatles [White Album]" };
       string[] row1 = { "1960", "6", "Fools Rush In", "Frank Sinatra", "Nice 'N' Easy" };
       string[] row2 = { "11/11/1971", "1", "One of These Days", "Pink Floyd", "Meddle" };
       string[] row3 = { "1988", "7", "Where Is My Mind?", "Pixies", "Surfer Rosa" };
       string[] row4 = { "5/1981", "9", "Can't Find My Mind", "Cramps", "Psychedelic Jungle" };
       string[] row5 = { "6/10/2003", "13", "Scatterbrain. (As Dead As Leaves.)", "Radiohead", "Hail to the Thief" };
       string[] row6 = { "6/30/1992", "3", "Dress", "P J Harvey", "Dry" };
    
       dataGridView1.Rows.Add(row0);
       dataGridView1.Rows.Add(row1);
       dataGridView1.Rows.Add(row2);
       dataGridView1.Rows.Add(row3);
       dataGridView1.Rows.Add(row4);
       dataGridView1.Rows.Add(row5);
       dataGridView1.Rows.Add(row6);
    
       dataGridView1.Columns[0].DisplayIndex = 3;
       dataGridView1.Columns[1].DisplayIndex = 4;
       dataGridView1.Columns[2].DisplayIndex = 0;
       dataGridView1.Columns[3].DisplayIndex = 1;
       dataGridView1.Columns[4].DisplayIndex = 2;
      }
    

     You just have to create your own unique object named panel1 panels on your form

     

    Bye

     


    Carmelo La Monica  http://community.visual-basic.it/carmelolamonica/

    Wednesday, June 29, 2011 9:31 PM

All replies

  • Hello LeeHyungGeun ,

     

    try this example of code, you can add all methods in the load evento in your form 1

     

      DataGridView dataGridView1 = new DataGridView();
    
      private void Form1_Load(object sender, EventArgs e)
      {
       SetupDataGridView();
       PopulateDataGridView();
      }
    
      private void SetupDataGridView()
      {
    
       this.panel1.Controls.Add(dataGridView1);
    
       dataGridView1.ColumnCount = 5;
    
       dataGridView1.Columns[0].Name = "Release Date";
       dataGridView1.Columns[1].Name = "Track";
       dataGridView1.Columns[2].Name = "Title";
       dataGridView1.Columns[3].Name = "Artist";
       dataGridView1.Columns[4].Name = "Album";
      }
    
      private void PopulateDataGridView()
      {
       string[] row0 = { "11/22/1968", "29", "Revolution 9", "Beatles", "The Beatles [White Album]" };
       string[] row1 = { "1960", "6", "Fools Rush In", "Frank Sinatra", "Nice 'N' Easy" };
       string[] row2 = { "11/11/1971", "1", "One of These Days", "Pink Floyd", "Meddle" };
       string[] row3 = { "1988", "7", "Where Is My Mind?", "Pixies", "Surfer Rosa" };
       string[] row4 = { "5/1981", "9", "Can't Find My Mind", "Cramps", "Psychedelic Jungle" };
       string[] row5 = { "6/10/2003", "13", "Scatterbrain. (As Dead As Leaves.)", "Radiohead", "Hail to the Thief" };
       string[] row6 = { "6/30/1992", "3", "Dress", "P J Harvey", "Dry" };
    
       dataGridView1.Rows.Add(row0);
       dataGridView1.Rows.Add(row1);
       dataGridView1.Rows.Add(row2);
       dataGridView1.Rows.Add(row3);
       dataGridView1.Rows.Add(row4);
       dataGridView1.Rows.Add(row5);
       dataGridView1.Rows.Add(row6);
    
       dataGridView1.Columns[0].DisplayIndex = 3;
       dataGridView1.Columns[1].DisplayIndex = 4;
       dataGridView1.Columns[2].DisplayIndex = 0;
       dataGridView1.Columns[3].DisplayIndex = 1;
       dataGridView1.Columns[4].DisplayIndex = 2;
      }
    

     You just have to create your own unique object named panel1 panels on your form

     

    Bye

     


    Carmelo La Monica  http://community.visual-basic.it/carmelolamonica/

    Wednesday, June 29, 2011 9:31 PM
  • thank you ~~
    Wednesday, June 29, 2011 9:42 PM
  • thank you ~~


    Hello LeeHyungGeun,

     

    you're welcome :)

     

    Bye


    Carmelo La Monica  http://community.visual-basic.it/carmelolamonica/
    Wednesday, June 29, 2011 9:44 PM
  • Do you mean in the designer? You can right click on the panel and select send to back (or right click on the datagridview and select bring to front) to change the z-order

    Please mark this as answer or vote as helpful if it solved your problem
    Thursday, June 30, 2011 11:07 AM
  • hi

    i want to use datagridview front of panel.

     

    but if i use that panel, that datagridview is hidding because of that panel.

     

    thank you~


    Try this code please:

    this.dataGridView1.Parent = this.panel2;
    

    Hope it helps. 


    Best Regards,
    Rocky Yue[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, July 1, 2011 9:00 AM
    Moderator