Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Stringgrid value validation

Posted on 2002-05-07
4
Medium Priority
?
557 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
[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
  • 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 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

609 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