Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. delete dataGridView row [modified]

delete dataGridView row [modified]

Scheduled Pinned Locked Moved Managed C++/CLI
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jashimu
    wrote on last edited by
    #1

    Hi everyone, I am having some deficulty delete dataGridView rows From My DataGridView. I tried following:

    for(int j =0;j<this->s_dataGridView->Rows->Count;j++)
    {
    this->s_dataGridView->Rows->RemoveAt(j);
    }

    and

    int j = this->s_dataGridView->RowCount;
    while(j<=0)
    {
    this->s_dataGridView->Rows->RemoveAt(j);
    rowCount --;
    }

    it seems like not working. Yes I found My own Solution this is how it works when the entire row collection is needed to delete;

    for each (System::Windows::Forms::DataGridViewRow^ row in this->securityCodedataGridView->Rows)
    {
    this->securityCodedataGridView->Rows->Remove(row);
    }

    modified on Monday, August 23, 2010 11:28 AM

    A L 2 Replies Last reply
    0
    • J jashimu

      Hi everyone, I am having some deficulty delete dataGridView rows From My DataGridView. I tried following:

      for(int j =0;j<this->s_dataGridView->Rows->Count;j++)
      {
      this->s_dataGridView->Rows->RemoveAt(j);
      }

      and

      int j = this->s_dataGridView->RowCount;
      while(j<=0)
      {
      this->s_dataGridView->Rows->RemoveAt(j);
      rowCount --;
      }

      it seems like not working. Yes I found My own Solution this is how it works when the entire row collection is needed to delete;

      for each (System::Windows::Forms::DataGridViewRow^ row in this->securityCodedataGridView->Rows)
      {
      this->securityCodedataGridView->Rows->Remove(row);
      }

      modified on Monday, August 23, 2010 11:28 AM

      A Offline
      A Offline
      Andreoli Carlo
      wrote on last edited by
      #2

      Explanation:

      //wrong code
      for(int j =0;j<this->s_dataGridView->Rows->Count;j++)
      {
          this->s_dataGridView->Rows->RemoveAt(j);
      }
      
      //right code
      // the rows goes from 0 to count-1
      for(int j =0;j<this->s_dataGridView->Rows->Count-1;j++)
      {
          this->s_dataGridView->Rows->RemoveAt(j);
      }
      

      and again

      //wrong code
      int j = this->s_dataGridView->RowCount;
      while(j<=0)
      {
         this->s_dataGridView->Rows->RemoveAt(j);
         rowCount --;
      }
      // right code
      int j = this->s_dataGridView->RowCount-1;
      while(j>=0)
      {
         this->s_dataGridView->Rows->RemoveAt(j);
         j--;
      }
      
      J 1 Reply Last reply
      0
      • A Andreoli Carlo

        Explanation:

        //wrong code
        for(int j =0;j<this->s_dataGridView->Rows->Count;j++)
        {
            this->s_dataGridView->Rows->RemoveAt(j);
        }
        
        //right code
        // the rows goes from 0 to count-1
        for(int j =0;j<this->s_dataGridView->Rows->Count-1;j++)
        {
            this->s_dataGridView->Rows->RemoveAt(j);
        }
        

        and again

        //wrong code
        int j = this->s_dataGridView->RowCount;
        while(j<=0)
        {
           this->s_dataGridView->Rows->RemoveAt(j);
           rowCount --;
        }
        // right code
        int j = this->s_dataGridView->RowCount-1;
        while(j>=0)
        {
           this->s_dataGridView->Rows->RemoveAt(j);
           j--;
        }
        
        J Offline
        J Offline
        jashimu
        wrote on last edited by
        #3

        Hi barbetto80, Thanks so much for your help. Sometimes little mistake can go very wrong. Now it is working. thanks again

        1 Reply Last reply
        0
        • J jashimu

          Hi everyone, I am having some deficulty delete dataGridView rows From My DataGridView. I tried following:

          for(int j =0;j<this->s_dataGridView->Rows->Count;j++)
          {
          this->s_dataGridView->Rows->RemoveAt(j);
          }

          and

          int j = this->s_dataGridView->RowCount;
          while(j<=0)
          {
          this->s_dataGridView->Rows->RemoveAt(j);
          rowCount --;
          }

          it seems like not working. Yes I found My own Solution this is how it works when the entire row collection is needed to delete;

          for each (System::Windows::Forms::DataGridViewRow^ row in this->securityCodedataGridView->Rows)
          {
          this->securityCodedataGridView->Rows->Remove(row);
          }

          modified on Monday, August 23, 2010 11:28 AM

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          the logical approach:

          while(RowCount!=0) Rows.RemoveAt(0);

          the smart approach:

          Rows.Clear();

          :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups