April 18, 2024, 01:03:26 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Conditional selection and reselection of item in a list box with calendar

Started by AdrianFox, November 22, 2011, 03:40:18 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AdrianFox

This is driving me mad, and I wonder if someone can just point me in the right direction in terms of the logic.  As will be apparent, my logical thought processes are not very good maybe!

Verbose description:  I am using a Calendar Control, an edit box, and a list control.   
When I click on a date in the calendar control, the program converts the date into a string (in the form of '10 November 2011' or whatever) and this is followed by a search of the list box items.  If an item in the list box contains that date (in string form) then the whole item is printed to the edit box.  The item remains highlighted in the list box so any changes made in the edit box are overwritten in the listbox when 'enter' is pressed in the edit box.  So far so good . My code works fine with this.

Problem
If the search finds NO item in the list box containing the date, then the string form of the date is printed in the edit box ready for a new item to be entered.  This is where the problem occurs as the previously highlighted in the listbox remains highlighted.  Pressing 'Enter' would overwrite this item (the wrong one).

I can use a 'Clear' button which removes highlighting in the listbox with the code below before editing my 'new' item .....

SETSELECTED D1,COMBO_1,-1 

but this is not very elegant and means the user must check to see if an item is highlighted before doing anything.

What I need to do is use some code to remove highlighting in the listbox when the string date item is NOT found in the search of the listbox. 

To my addled brain, the following SHOULD work....  (mystring is the string for the listbox item, searchstring is the verbose date string, and pos is the position of the item in the listbox. )  Setselected -1 works to remove all highlighting in the listbox. 

if mystring="":SETSELECTED D1,COMBO_1,-1:elseif instr(ucase$(mystring),searchstring)>0:setcontroltext d1,editbox_3,mystring:setselected d1,combo_1,pos:endif 'both terms must be UCASE


However the above code (and variations on it at various positions in the program) always removes the selection in the list box, even when the mystring string is NOT "".   Something is clearly wrong with my logic but I have not been able to work out where I'm going wrong or how to work around it.

Thanks.
???
Adrian Fox

billhsln

I am no expert, but your code:

if mystring=""
  SETSELECTED D1,COMBO_1,-1
elseif instr(ucase$(mystring),searchstring)>0
setcontroltext d1,editbox_3,mystring
setselected d1,combo_1,pos
endif


Seems to be missing an ELSE for the >0 condition, so if condition is 0 or less, you do nothing.  I had to put it on multiple lines and add spacing.  Yes, the :'s do signify a new line, but trying to read the code is too hard to see where you are or follow what you are doing for me.

Bill
When all else fails, get a bigger hammer.

AdrianFox

Thanks Bill.  I have just discovered that all I need to do is to put SETSELECTED D1,COMBO_1,-1 at the start of the calendar control handling as this clears the list box prior to doing anything else.
CASE @IDCONTROL
'calendar handler here
CONST MCN_SELECT = (MCN_FIRST + 4)
if @controlid=idcalendar
if @notifycode=MCN_SELECT Then 
'CALENDAR CONTROL HANDLING BELOW
  'reads the calendar control and sets the date into verbose fashion and displays on screen when clicked
SETCONTROLTEXT D1,EDITBOX_3,""
SETSELECTED D1,cOMBO_1,-1  'PUTTING CLEAR SELECTION HERE AVOIDS SELECTION WHEN NOT WANTED
ccGetCurSel d1,idcalendar,m,d,y


Took me several hours but I guess I should sit down with the program printed on paper and trace through the logical flow step by step from the start.

Thanks for your help.

:-[
Adrian Fox