Solved

Remove some blank lines in stringgrid (500 points)

Posted on 2008-10-31
2
452 Views
Last Modified: 2013-11-23
I have a stringgrid. When the user clicks on any row, a form is displayed with editboxes,  When this form is closed, the contents of these editboxes are transferred to each column of the CLICKED on row of the stringgrd.

I want a single blank row to be inserted above and another single blank row inserted below this row when the info is copied to the stringgrid. The stringgrid must always be double spaced:
Blank row
Row contaiing info
Blank row
Row contaiing info
Blank row
Row contaiing info    
etc, etc.

I use Delphi6. I am giving 500 points as this is urgent, together with my grateful thanks.
0
Comment
Question by:rincewind666
2 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 500 total points
ID: 22865155
a sample (the grid starts with a empty line, fixcols/fixrows are set)

unit stg_u1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids;

const
  stgInserting = false;
  stgEditing = true;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    procedure StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    fEditMode : Boolean; //False= Inserting, True= Editing
    procedure InsertLine(AtRow : Integer);
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

uses stg_u2;  //the edit-form

{$R *.dfm}


procedure TForm1.InsertLine(AtRow : Integer);
var r,c : integer;
begin
  if AtRow > StringGrid1.Row then
    raise Exception.Create('Index ['+inttostr(AtRow)+'] out of Bounds');
  StringGrid1.Rowcount := StringGrid1.Rowcount + 1;
  for r :=  StringGrid1.Rowcount - 1 downto AtRow + 1 do
    for c := 0 to StringGrid1.Colcount - 1 do
      StringGrid1.Cells[c,r] := StringGrid1.Cells[c,r-1];

  for c := 0 to StringGrid1.Colcount - 1 do
    StringGrid1.Cells[c,AtRow] := '';
end;

procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  f : TForm2;
  mr : integer;
  r : integer;
begin
  f := TForm2.create(self);
  try
    if (stringGrid1.Cells[1,stringGrid1.row] <> '') or
       (stringGrid1.Cells[2,stringGrid1.row] <> '') then
    begin
      fEditMode := stgEditing;
      f.edit1.Text := stringGrid1.Cells[1,stringGrid1.row];
      f.edit2.Text := stringGrid1.Cells[2,stringGrid1.row];
    end
    else
      fEditMode := stgInserting;
    mr := f.showmodal;
    if mr = mrOK then
    begin
      if fEditMode = stgInserting then
      begin
        //add two empty Lines;
        InsertLine(stringGrid1.row);
        InsertLine(stringGrid1.row);
        stringGrid1.row := stringGrid1.row + 1;
      end;
      stringGrid1.Cells[1,stringGrid1.row] := f.edit1.Text;
      stringGrid1.Cells[2,stringGrid1.row] := f.edit2.Text;
    end;
  finally
    f.Release;
  end;
end;
end.

meikl ;-)
0
 

Author Comment

by:rincewind666
ID: 22871145
Many thanks meikl.  Greatly appreciated.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now