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
Solved

Stringgrid value validation

Posted on 2002-05-07
4
522 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
ID: 6994083
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
ID: 6994086
working sample may follow . . .
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 6994599
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
ID: 6994785
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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