Author Topic: SETCONTROLTEXT in a ComboBox Control.  (Read 1266 times)

0 Members and 1 Guest are viewing this topic.

Offline Egil

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 896
    • LA2PJ
SETCONTROLTEXT in a ComboBox Control.
« on: April 30, 2017, 11:32:20 AM »
I'm trying to set the text in a controlbox before any items are selected. Never done this before, but according to the User Guide, it should be a walk in the park.
There must be something I'm missing though. Whatever I try, the result is the same: no text.
As shown in the example below, I try to put the string "Select:" in the control box at startup. Can anyone see what I do wrong?


Egil


Code: [Select]
' ComboBox.cba

AutoDefine "Off"

def wstyle:int
wstyle = @SIZE|@MINBOX|@MAXBOX

def win:window 

def cleft,ctop,cwidth,cheight:int :'Clientarea
def run,i:int 

Window win,-640,0,640,480,wstyle,0,"  CB ComboBox Test",MainLoop
SETWINDOWCOLOR win,RGB(240,202,86)

CONTROL win,"M,Select,10,10,160,202,@CTCOMBODROPLIST|@VSCROLL,11" :' ComboBox Control

SETCONTROLTEXT win,11,"Select:"   :' THIS DOES NOT WORK!!!!!!!!!!!!!!!

for i = 1 to 50
addstring win,11,"Item "+str$(i)
next i

run=1

WAITUNTIL run = 0 
CLOSEWINDOW win 
END 

'
SUB MainLoop()
'-------------------------------------------------------------------------------------
SELECT @CLASS
 
CASE @IDCREATE 
CENTERWINDOW win

CASE @IDCLOSEWINDOW 
run = 0 

ENDSELECT 
RETURN
'-------------------------------------------------------------------------------------

Support Amateur Radio  -  Have a ham  for dinner!

Online Brian Pugh

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 1022
  • Hobby Programmer
Re: SETCONTROLTEXT in a ComboBox Control.
« Reply #1 on: May 01, 2017, 03:12:31 AM »
Egil,

Instead of the SETCONTROLTEXT line, try these two lines instead:

ADDSTRING win,11,"Select"
SETSELECTED win,11,0

Brian

Offline Egil

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 896
    • LA2PJ
Re: SETCONTROLTEXT in a ComboBox Control.
« Reply #2 on: May 01, 2017, 04:16:21 AM »
Thanks Brian!

Your solution works just fine.



egil
Support Amateur Radio  -  Have a ham  for dinner!

Online Brian Pugh

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 1022
  • Hobby Programmer
Re: SETCONTROLTEXT in a ComboBox Control.
« Reply #3 on: May 01, 2017, 06:15:09 AM »
Good - glad it worked. Because you were populating the combobox with values from 1 to 50, there was room for a value to be set at position 0, as comboboxes start at zero, anyway

Brian

Offline Egil

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 896
    • LA2PJ
Re: SETCONTROLTEXT in a ComboBox Control.
« Reply #4 on: May 01, 2017, 07:32:18 AM »
Brian,

As you probably know, I have given the free version of CB to some very young kid so they can learn how to program windows in an easier way than they do by using the official tools that the school authorities have purchased. They use the SCRATCH and PYTHON languages for teaching programming, since they both are multiplatform languages, and the documentation is in norwegian.

These kids are new to the english language, so they are not able to understand much of the User Guide. Still they find CB easier to learn, maybe because they learn by seeing examples. Most of the time they are able to expand the examples to reach new levels of knowledge. But if they become stuck, they call me for an explanation. This ComboBox example is such a question, and one I was not able to figure out myself....

The values in position 1 to 50 was put there to show how they can add new items to the list.

Support Amateur Radio  -  Have a ham  for dinner!

Offline ckoehn

  • Sr. Member
  • ****
  • Posts: 372
Re: SETCONTROLTEXT in a ComboBox Control.
« Reply #5 on: May 01, 2017, 04:08:56 PM »
Egil,

The problem is that you set the control flag as "CTCOMBODROPLIST".  That control has no edit box to set.  You needed "CTCOMBODROPDOWN".

Code: [Select]
' ComboBox.cba

AutoDefine "Off"

def wstyle:int
wstyle = @SIZE|@MINBOX|@MAXBOX

def win:window 

def cleft,ctop,cwidth,cheight:int :'Clientarea
def run,i:int 

Window win,-640,0,640,480,wstyle,0,"  CB ComboBox Test",MainLoop
SETWINDOWCOLOR win,RGB(240,202,86)

CONTROL win,"M,Select,10,10,160,202,@CTCOMBODROPDOWN|@VSCROLL,11" :' ComboBox Control

SETCONTROLTEXT win,11,"Select:"   :' THIS DOES NOT WORK!!!!!!!!!!!!!!!

for i = 1 to 50
addstring win,11,"Item "+str$(i)
next i

run=1

WAITUNTIL run = 0 
CLOSEWINDOW win 
END 

'
SUB MainLoop()
'-------------------------------------------------------------------------------------
SELECT @CLASS
 
CASE @IDCREATE 
CENTERWINDOW win

CASE @IDCLOSEWINDOW 
run = 0 

ENDSELECT 
RETURN
'-------------------------------------------------------------------------------------

Later,
Clint

Offline Egil

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 896
    • LA2PJ
Re: SETCONTROLTEXT in a ComboBox Control.
« Reply #6 on: May 02, 2017, 02:46:41 AM »
Thanks Clint!

I'll pass on that information.
To be honest the biggest problem is lack of knowledge of the kind you pinpoint.
But then, cases like this is what make the coding hobby so facinating.


Hope all is well with you!


Egil
Support Amateur Radio  -  Have a ham  for dinner!

Online Brian Pugh

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 1022
  • Hobby Programmer
Re: SETCONTROLTEXT in a ComboBox Control.
« Reply #7 on: May 02, 2017, 04:03:58 AM »
Good one, Clint - didn't know that. I shall look up all the options now

Brian

Online Brian Pugh

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 1022
  • Hobby Programmer
Re: SETCONTROLTEXT in a ComboBox Control.
« Reply #8 on: May 02, 2017, 07:58:47 AM »
According to my attached combo sample, only the Dropdown and Simple combobox styles allow you to preset a value

A Drop List shows the clicked item from the list, and is not editable, and can't be preset UNLESS you add a value, and set the selection to it, and then add your list of data, as in the sample program

A Dropdown shows the clicked item from the list, and IS editable, and can be preset

A Simple combobox shows the list always, and when an item is clicked on, it will show in the edit box, and IS editable, as well, and can be preset (I like this one!)

Doesn't matter whether you preset a value before or after adding a list of data, it still works with the Dropdown and Simple styles

Now we need some clever dicky to work out how to type a value in and automatically search down the combobox for a match!

I did this really to work out in my own head how it all worked - feel free to shoot me down in flames if there is anything wrong

Brian

Offline billhsln

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 794
Re: SETCONTROLTEXT in a ComboBox Control.
« Reply #9 on: May 02, 2017, 10:03:30 AM »
Could you explain a little better on what you are looking for in this statement:

Quote
Now we need some clever dicky to work out how to type a value in and automatically search down the combobox for a match!

Would you want info entered into an Edit box or into the Combobox directly?  Plus to make the search work based on your program, I would change to the following code to make it more unique.

Code: [Select]
FOR add=1 TO 25
ADDSTRING d1,COMBO_1,USING("0##",ADD)+" Drop List"
ADDSTRING d1,COMBO_2,USING("0##",ADD)+" Dropdown"
ADDSTRING d1,COMBO_3,USING("0##",ADD)+" Simple"
NEXT add

Would make it easier to do a search, since they are not all alike.

Bill
« Last Edit: May 02, 2017, 10:06:27 AM by billhsln »
When all else fails, get a bigger hammer.

Online Brian Pugh

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 1022
  • Hobby Programmer
Re: SETCONTROLTEXT in a ComboBox Control.
« Reply #10 on: May 02, 2017, 11:18:13 AM »
Bill,

Simply put, if you had a Dropdown or Simple list, with a few random entries in the list, you could maybe type something like "w" and the cursor would drop down to the first entry that began with a "w"
If you typed "wo" it would drop further down the list to the nearest entry that started with something like "wo"
I don't particularly need the function myself, just thought it would be nice

Brian

Offline Egil

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 896
    • LA2PJ
Re: SETCONTROLTEXT in a ComboBox Control.
« Reply #11 on: May 02, 2017, 11:19:45 AM »
Brian,

I like your demo. This should be added to the example code included with the IWB package. In addition, converting to CB should be easy.

Two questions though. Why do you use:
Code: [Select]
CONTROL d1,@COMBOBOX,"Simple",345,30,125,260,0x50800601|@VSCROLL,COMBO_3
instead of:
Code: [Select]
CONTROL d1,@COMBOBOX,"Simple",345,30,125,260,@CTCOMBOSIMPLE|@VSCROLL,COMBO_3
I think that for newbies it would be easier to read the code if the flag names are used instead of the actual values. (myself included!!!)

And finally, how did you come up with the flag hex-value in the dialog definition:
Code: [Select]
CREATEDIALOG d1,0,0,500,300,0x80CB0080,0,"Combobox Example",&d1_handler

Egil
Support Amateur Radio  -  Have a ham  for dinner!

Online Brian Pugh

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 1022
  • Hobby Programmer
Re: SETCONTROLTEXT in a ComboBox Control.
« Reply #12 on: May 02, 2017, 11:47:16 AM »
Egil,

The hex values are inserted when you use the Dialog Creator function of IWB. On your other point, about typing the constants manually, I tried to think of a way to put in @CTCOMBO, etc, as a constant. That's why I added the @VSCROLL constant manually, rather than let IWB do it for me

Edit: OK, I think you can do it this way: 0x50800000|@CTCOMBODROPLIST|@VSCROLL

Brian

Offline Egil

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 896
    • LA2PJ
Re: SETCONTROLTEXT in a ComboBox Control.
« Reply #13 on: May 02, 2017, 11:59:57 AM »
Thanks Brian!

I tend to forget the Dialog Creator, and have not yet tried it. But looks like it has some advantages when it comes to style values compared to using the flag names, as I have never been able to get other than the close  button when doing it "by hand".


Egil
Support Amateur Radio  -  Have a ham  for dinner!

Offline LarryMc

  • Administrator
  • Hero Member
  • *****
  • Posts: 5929
  • 'All I like is finishing'
Re: SETCONTROLTEXT in a ComboBox Control.
« Reply #14 on: May 02, 2017, 02:15:16 PM »
Just a note:  In my IWB+ Visual Designer I have all the styles/flags names displayed as opposed to the values.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Offline billhsln

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 794
Re: SETCONTROLTEXT in a ComboBox Control.
« Reply #15 on: May 02, 2017, 04:07:04 PM »
I would look into @CBNEDITCHANGE and then select text and setup a search into the comboboxes and have it select the first match.  I think every time you enter a character this property would be set on.

Doc says this will work on Simple or Drop Down.

Bill

When all else fails, get a bigger hammer.