March 28, 2024, 02:39:11 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


SETCONTROLTEXT in a ComboBox Control.

Started by Egil, April 30, 2017, 11:32:20 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Egil

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


' 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!

Brian

Egil,

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

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

Brian

Egil

Thanks Brian!

Your solution works just fine.



egil
Support Amateur Radio  -  Have a ham  for dinner!

Brian

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

Egil

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!

ckoehn

Egil,

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

' 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

Egil

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!

Brian

Good one, Clint - didn't know that. I shall look up all the options now

Brian

Brian

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

billhsln

May 02, 2017, 10:03:30 AM #9 Last Edit: May 02, 2017, 10:06:27 AM by billhsln
Could you explain a little better on what you are looking for in this statement:

QuoteNow 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.

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
When all else fails, get a bigger hammer.

Brian

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

Egil

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:
CONTROL d1,@COMBOBOX,"Simple",345,30,125,260,0x50800601|@VSCROLL,COMBO_3

instead of:
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:
CREATEDIALOG d1,0,0,500,300,0x80CB0080,0,"Combobox Example",&d1_handler


Egil
Support Amateur Radio  -  Have a ham  for dinner!

Brian

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

Egil

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!

LarryMc

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

billhsln

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.