Solved

Remove some blank lines in stringgrid (500 points)

Posted on 2008-10-31
2
464 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sync project in eclipse locally 2 137
Add jar to project library in intellij idea 3 404
error when checking java version 4 4,878
How to navigate in javascript code from Intellij Idea 2 52
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. …
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

685 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