Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

Using changing event of list view to validate data,and setting focus back to the earlier selection if validation fails.

Hi,

I am trying to use the Changing event of list view to validate data entry. If the validation fails the change in selection should not be allowed. But i am getting into problems while using this event. Please help me out to implement this with an example.

Regards, Ravindra
0
brravi_74
Asked:
brravi_74
  • 3
1 Solution
 
mocartsCommented:
i have this tested with no problem (access is allowd only on first four items):

procedure TForm1.ListView1Changing(Sender: TObject; Item: TListItem;
  Change: TItemChange; var AllowChange: Boolean);
begin
  if Item.Index > 3 then AllowChange := False;
end;

wbr, mo.
0
 
brravi_74Author Commented:
Hi,

My actual problem is that in the changing event i have written a validation function which should be called once during the change. The function return decides whether the change should be allowed or not. This function is getting called twice/thrice. How can i sort out this?

Regards, Ravindra
0
 
mocartsCommented:
I don't know why listView sends Selected Item twice before changing..
but puting in the begining of event handler code belov solves your problem:

if Item = TListView(Sender).Selected then exit;

i.e.
procedure TForm1.ListView1Changing(Sender: TObject; Item: TListItem;
 Change: TItemChange; var AllowChange: Boolean);
begin
 if Item = TListView(Sender).Selected then exit;
 if Item.Index > 3 then AllowChange := False;
end;

wbr, mo.
0
 
mocartsCommented:
now I know why.. it's because ListView uses this event as notification about State change on Selected item, too
so it first notifies that Selected is going to change the state after that it notifies that Selected is going to loose Focus and, at last, notifies which Item will be Selected and asks for accept.

wbr, mo.
0
 
CleanupPingCommented:
brravi_74:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now