Solved

Remove some blank lines in stringgrid (500 points)

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
populate value from mongo db in java 98 365
Angular JS Route 3 83
Visual Studio 2013 and Eclipse Neon 6 48
JavaFX TableView not displaying correctly 3 55
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

839 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