CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2011
    Location
    Greece
    Posts
    26

    Post StringGrid,delete last row

    Goodmorning
    I have a small problem with my application. I have an Edit1 from where i put values in StringGrid.
    I want to make a button where i will put the above code. with this button the user will delete the last row of the stringgrid.
    When he write again on Edit it will put it in the after the last record. I write the above but dont work right. I just want from the user delete the last row

    Code:
    	const int row_count = StringGrid1->RowCount;
    
    	// (1) shift the contents of the trailing columns
    	for (int row =1; row < row_count - 1; ++row)
    	{
    	  StringGrid1->Rows[row] = StringGrid1->Rows[row + 1];
    	}
    
    	// (2) remove the last row
    	StringGrid1->RowCount = row_count -1;

  2. #2
    Join Date
    Nov 2012
    Location
    Kolkata, WestBengal, India
    Posts
    15

    Re: StringGrid,delete last row

    As you just want to delete the last row, you can just point your last Row to the Second Last Row - as you have done in your code -
    // (2) remove the last row
    StringGrid1->RowCount = StringGrid1->RowCount - 1;
    Now, what eactly do you want to do for adding a new row?
    - add it at the end (use this) ?
    const int row_count = StringGrid1->RowCount;
    StringGrid1->Rows[row_count] = <your new data>;
    StringGrid1->RowCount = row_count + 1;
    or,
    - add it at the begining?
    - by moving/shifting the Rows to downwards and deleting the last row?
    - or overwriting the first row and keep the other rows as it is?

    Raju2001006

    Please put [CODE][/CODE] tags around your code to preserve indentation and make it more readable...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured