Page 1 of 1

Posted: Wed Mar 20, 2002 3:50 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.

A few questions regarding Gadget States...

1. How do you clear the text in a ComboBox? The manual says you can use SetGadgetText but that does nothing.

2. How can you cancel a selection in a ComboBox or ListGadget (set the index back to -1)? The lowest SetGadgetState will go is 0. I don't want to have to clear the entire list and reload it, this looks really bad.

Posted: Wed Mar 20, 2002 4:40 pm
by BackupUser
Restored from previous forum. Originally posted by fred.


For now, you can't. I will add it for v3.0. Thanks for your remark !



Fred - AlphaSND

Posted: Wed Mar 20, 2002 7:10 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.

Looking forward to v3.0 :)

Thanks Fred.

Posted: Thu Mar 21, 2002 11:57 am
by BackupUser
Restored from previous forum. Originally posted by Stan.

Hi Paul,

Sorry Fred, but YES you can ( if I understand well what you want ... )
Check that :
______________________________________________

CB_DELETESTRING.w = $144

InitGadget( 10 )
Main_hWnd = OpenWindow( 0, 0, 0, 400, 300, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget, "Guitar Pure Basic Tutor" )
Dim G_string.s( 7 )
G_string( 0 ) = "0"
G_string( 1 ) = "1"
G_string( 2 ) = "2"
G_string( 3 ) = "3"
G_string( 4 ) = "4"
G_string( 5 ) = "5"
G_string( 6 ) = ""

Butt_Str.s
Save_s.s
Save_Index.l
Long_null.l = 0
G_state.w = 3

If Main_hWnd
If CreateGadgetList( Main_hWnd )
Combo_n = ComboBoxGadget( 1, 20, 30, 80, 80 )
i = 0
While Len( G_string( i ) )
n=AddGadgetItem( 1, -1, G_string(i) )
i = i + 1
Wend
SetGadgetState( 1, G_state )
Butt_Str = "Erase "
ButtonGadget( 2, 20, 200, 80, 20, Butt_Str )
Butt_Str = "Restore "
ButtonGadget( 3, 20, 240, 80, 20, Butt_Str )

EndIf ; CreateGadgetList( Main_hWnd )

Repeat ; EventID = #PB_EventCloseWindow
Repeat
EventID.l = WaitWindowEvent( )
Until EventID0

If EventID = 307 ; ITS A HACK TO GET COMBO RESPONSE DON'T ASK WHY IT WORKS ... IT DOES !

n = GetGadgetState( 1 )
If n G_state
G_state = n
SetGadgetState( 1, G_state )
EndIf ; n G_state
Else ; If EventID = 307
If EventID = #PB_EventGadget
Select EventGadgetID()
Case 2 ; Delete item
Save_s = G_string( G_state )
Save_Index = G_state
SendMessage_( Combo_n, CB_DELETESTRING, G_state, Long_Null)
SetGadgetState( 1, G_state )
Case 3 ; Insert it again
AddGadgetItem( 1, Save_Index, G_string( Save_Index ) )
SetGadgetState( 1, Save_Index )
EndSelect
EndIf ; EventID = #PB_EventGadget
EndIf ; EventID = 307
Until EventID = #PB_EventCloseWindow
EndIf ; Main_hWnd

___________________________________

I made it short (no check on buttons ... ) Make it bulletproof.

Hope this helps.




Learning and Love are what life is all about ... [ PB. registered user ]

Posted: Thu Mar 21, 2002 3:30 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.

Hi Stan,

Sorry but you misunderstood.
Fred knows what I'm talking about...

Say you have a list of items in a combobox or listview. If you were to check the gadgetstate it would return -1 because nothing has been selected yet.
Then you highlight one of them (because you are going to make a selection). Normally getgadgetstate would return the index (or position) of the selected item in the list... but wait... you decide you do not want to select any items so you press a Clear or Cancel button (that also exists on the form) and use setgadgetstate to -1 because you do not want any items selected.

-1 does not work. The lowest you can use is 0 but this will select the first item in the list.

At this time all you can do is clear the combobox or listview and reload it with your data but if you have 500 or more items... you see the refresh happening and this looks sloppy (and it slows things down)

Posted: Thu Mar 21, 2002 4:29 pm
by BackupUser
Restored from previous forum. Originally posted by fred.


As always, an API workaround is possible... Don't have the time to search for it now..

Fred - AlphaSND

Posted: Fri Mar 22, 2002 9:02 am
by BackupUser
Restored from previous forum. Originally posted by Stan.

Hi Paul,

Sorry about the misunderstanding ... Fred is right, you can do it ( if I get
it right that time ... )
______________________________________________________________

CB_SETCURSEL.w = $14E

InitGadget( 10 )
Main_hWnd = OpenWindow( 0, 0, 0, 400, 300, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget, "Guitar Pure Basic Tutor" )
Dim G_string.s( 7 )
G_string( 0 ) = "0"
G_string( 1 ) = "1"
G_string( 2 ) = "2"
G_string( 3 ) = "3"
G_string( 4 ) = "4"
G_string( 5 ) = "5"
G_string( 6 ) = ""

Butt_Str.s
Long_null.l = 0
G_state.w
Word_Minus1.w = -1

OpenConsole( )

If Main_hWnd
If CreateGadgetList( Main_hWnd )
Combo_n = ComboBoxGadget( 1, 20, 30, 80, 80 )
i = 0
While Len( G_string( i ) )
n=AddGadgetItem( 1, -1, G_string(i) )
i = i + 1
Wend
;SetGadgetState( 1, G_state )
Butt_Str = "Cancel Item"
ButtonGadget( 2, 20, 200, 120, 20, Butt_Str )
Butt_Str = "Check State"
ButtonGadget( 3, 20, 240, 120, 20, Butt_Str )

EndIf ; CreateGadgetList( Main_hWnd )

PrintN("Start Value "+Str(GetGadgetState(1)))

Repeat ; EventID = #PB_EventCloseWindow
Repeat
EventID.l = WaitWindowEvent( )
Until EventID0

If EventID = 307 ; ITS A HACK TO GET COMBO RESPONSE DON'T ASK WHY IT WORKS ... IT DOES !

n = GetGadgetState( 1 )
If n G_state
G_state = n
SetGadgetState( 1, G_state )
EndIf ; n G_state
Else ; If EventID = 307
If EventID = #PB_EventGadget
Select EventGadgetID()
Case 2 ; Cancel
SendMessage_( Combo_n, CB_SETCURSEL, Word_Minus1, Long_Null)
Case 3 ; Check State
n = GetGadgetState( 1 )
PrintN("State = "+Str(n) )
EndSelect
EndIf ; EventID = #PB_EventGadget
EndIf ; EventID = 307
Until EventID = #PB_EventCloseWindow
EndIf ; Main_hWnd
CloseConsole( )
End
_____________________________________________________

Hope this is it !



Learning and Love are what life is all about ... [ PB. registered user ]

Posted: Fri Mar 22, 2002 3:09 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.

Three cheers for Stan !!!

Nice work my friend... That's what I was looking for.
Now if I could just find a similar command to do this with a ListIconGadget...

ps. Fred: still put this ability into v3 :)



Edited by - paul on 22 March 2002 16:43:42

Posted: Sat Mar 23, 2002 8:51 pm
by BackupUser
Restored from previous forum. Originally posted by fred.

I've test it with the ComboBox and the SetGadgetState() command works correctly if passing -1. What is the problem ?

Fred - AlphaSND

Posted: Sat Mar 23, 2002 10:25 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.

Wow, that is very strange Fred.
After reading your post I went back and tried again and this time using -1 with SetGadgetState and a ComboBox worked properly.

Hmmm... honestly I'm not going crazy! It didn't work the other day, today it works.

Well, regardless, can you make it work for ListIconGadgets too??
I know it still doesn't work with these. :)

Posted: Sat Mar 23, 2002 10:48 pm
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.
Wow, that is very strange Fred.
After reading your post I went back and tried again and this time using -1 with SetGadgetState and a ComboBox worked properly.

Hmmm... honestly I'm not going crazy! It didn't work the other day, today it works.

Well, regardless, can you make it work for ListIconGadgets too??
I know it still doesn't work with these. :)
Hey Paul, I asked for those on IRC recently and Fred said he would them in V3. Yayayay!

Fangles