?
Solved

Remove some blank lines in stringgrid (500 points)

Posted on 2008-10-31
2
Medium Priority
?
477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
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 column That will then direct you to their download page. From that p…
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 synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month14 days, 2 hours left to enroll

801 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