Solved

Stringgrid value validation

Posted on 2002-05-07
4
504 Views
Last Modified: 2010-04-04
When I want to enter a value into a string grid cell (eg: StringGrid1.Cells[2,1]) I want to check whether that same value exists either in the same column  or in the same row. It's some kind of a validation process whereby, I would be able to assign some value to the cell if only the same value does not exist in the same column or row.

sorry for my English.

thnks
0
Comment
Question by:drnadeem
  • 3
4 Comments
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
well, you could use

//for same row
if stringgrid1.rows[rowindex].IndexOf('VALUE') > -1 then
  showmessage('Exists Already');

//for same column
if stringgrid1.cols[colindex].IndexOf('VALUE') > -1 then
  showmessage('Exists Already');

just as kickoff
(just clear and save your current input before validating)

not sure about syntax->just from head

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
working sample may follow . . .
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
Comment Utility
a working sample

unit stringgrid_validate_u;

interface

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

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
var
  ssave : String;
  c,r : integer;
begin
  c := stringgrid1.Col;
  r := stringgrid1.Row;
  ssave := StringGrid1.Cells[c,r];
  StringGrid1.Cells[c,r] := '';
  canselect := ((StringGrid1.Rows[stringgrid1.Row].IndexOf(ssave) = -1) and //checkrow
               (StringGrid1.Cols[stringgrid1.Col].IndexOf(ssave) = -1)) or  //checkCol
               (ssave = '');  //empty is allowed
  StringGrid1.Cells[c,r] := ssave;
  if not canselect then
    showmessage('Value already exists!');
end;

end.

hope this helps

meikl ;-)
0
 
LVL 2

Expert Comment

by:PeterLarsen
Comment Utility
I haven't read the entire question with comments, but if you want to search through a row or a column i guess you can use IndexOf. StringGrid1.Rows[xx].IndexOf('search text');
And again, i don't know whether this have been suggested by kretzs.. !
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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

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

12 Experts available now in Live!

Get 1:1 Help Now