?
Solved

Stringgrid value validation

Posted on 2002-05-07
4
Medium Priority
?
547 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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