Solved

Remove some blank lines in stringgrid (500 points)

Posted on 2008-10-31
2
449 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
Comment Utility
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
Comment Utility
Many thanks meikl.  Greatly appreciated.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
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.

772 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

10 Experts available now in Live!

Get 1:1 Help Now