?
Solved

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

Posted on 2003-03-20
7
Medium Priority
?
170 Views
Last Modified: 2010-04-03
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
Comment
Question by:brravi_74
[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
7 Comments
 
LVL 9

Expert Comment

by:mocarts
ID: 8173877
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
 

Author Comment

by:brravi_74
ID: 8178899
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
 
LVL 9

Accepted Solution

by:
mocarts earned 200 total points
ID: 8179731
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
 
LVL 9

Expert Comment

by:mocarts
ID: 8179750
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
 

Expert Comment

by:CleanupPing
ID: 9316654
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.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 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