Readonly Combobox - is this OK

Everything else that doesn't fall into one of the other PB categories.
leodh
Enthusiast
Enthusiast
Posts: 164
Joined: Sun Nov 06, 2005 6:07 am
Location: Perth Western Australia

Readonly Combobox - is this OK

Post by leodh »

Hi,

I have been trying to find a solution to the problem of a readonly Combobox Gadget, I have searched the forum but have not been able to find a suitable solution, the only one that looked good was to grey - disable some of the items, but for the life of me every time I tranfered the code into my application it did not work, something to do with the callback?

Anyway I found a solution that seems to work but I am not should if it is really the right way to go.

Code: Select all

Enumeration
#Window1
#WhoText
#Who
#Review
#Restore
#Quit

EndEnumeration


Global Off.i

Dim Officer.s(80)

Details.s = "List Officer.txt"
If ReadFile(0,Details.s) 
  Off.i = 0
  While Eof(0) = 0
    Off = Off + 1
    Officer.s(Off) = ReadString(0)
  Wend
CloseFile(0)
Else
   MessageRequester("Information","Couldn't open the" + Chr(10) + Chr(10) + Details.s + Chr(10) + Chr(10) + " Please check network connection.",0|#MB_ICONWARNING)
EndIf

OpenWindow(#Window1, 0, 0,300,170,"Combo Box Readonly",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
  TextGadget     (#WhoText, 25, 20,110, 20," Who is responsible",#PB_Text_Border)
  ComboBoxGadget (#Who,    125, 20,140, 20)
  ButtonGadget   (#Review, 100, 60,105, 20," Review")
  ButtonGadget   (#Restore,100, 90,105, 20," Restore")
  ButtonGadget   (#Quit,   100,120,105, 20," Quit")

For a = 1 To Off.i
    AddGadgetItem(#Who,-1,Officer.s(a))
Next a

Repeat

EventID = WaitWindowEvent() 
  
  If EventID = #PB_Event_Gadget
      
    Select EventGadget()
    
      Case #Review
        Gosub ReadOnly
        
      Case #Restore
        Gosub RestoreList
        
      Case #Quit
        End
      
    EndSelect
      
  EndIf
      
Until EventID = #PB_Event_CloseWindow 
End 
 
Readonly:
  Result = GetGadgetState(#Who)
  Result$ = GetGadgetItemText(#Who,Result)
  ClearGadgetItems(#Who)
  AddGadgetItem(#Who,-1,Result$)
  SetGadgetText(#Who,Result$)
Return

RestoreList:
ClearGadgetItems(#Who)
For a = 1 To Off.i
  AddGadgetItem(#Who,        -1,Officer.s(a))
Next a
Return 
It seems to work and I have had no problems yet, can anyone see any problems using this?

Thanks
Leo
Regards
Leo
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: Readonly Combobox - is this OK

Post by tinman »

Why not just use DisableGadget(#Who, #True) when you click on "Review" and DisableGadget(#Who, #False) when you click on "Restore"?
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
leodh
Enthusiast
Enthusiast
Posts: 164
Joined: Sun Nov 06, 2005 6:07 am
Location: Perth Western Australia

Re: Readonly Combobox - is this OK

Post by leodh »

@ tinman

I tried that but it greys out the gadgets text making it hard to read, and I want the user to be able to see the selected text.

regards
leo
Regards
Leo
User avatar
Shardik
Addict
Addict
Posts: 2079
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Readonly Combobox - is this OK

Post by Shardik »

Did you take a look into these code examples from me?
http://www.purebasic.fr/english/viewtopic.php?t=33044

Because of internal changes in the ComboBoxGadget from
PB 4.20 to later versions (the Height parameter does not
longer represent the height of the dropdown box but the
height of the edit box) you have to change the height value
in the combo box definition from 150 to 20...
Collection of cross-platform examples with API functions to extend PureBasic
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: Readonly Combobox - is this OK

Post by tinman »

leodh wrote:I tried that but it greys out the gadgets text making it hard to read, and I want the user to be able to see the selected text.
Ah, OK.

IMO a ComboBoxGadget is not the best way to indicate some read only data, since it's purpose is to select 1 of many options (or a user entered option in the case of editable comboboxes).

An alternative would be to have a hidden readonly StringGadget. The background will be grey but the text will stay black (at least on the Windows Classic colour scheme). When you call the ReadOnly routine you could set the text from the ComboBoxGadget into the StringGadget, hide the ComboBoxGadget and show the StringGadget.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
leodh
Enthusiast
Enthusiast
Posts: 164
Joined: Sun Nov 06, 2005 6:07 am
Location: Perth Western Australia

Re: Readonly Combobox - is this OK

Post by leodh »

@ Shardik

Thats great must of used the wrong wording for my search.

thanks again

leo
Regards
Leo
Post Reply