Page 1 of 1

Readonly Combobox - is this OK

Posted: Mon Nov 30, 2009 2:42 am
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

Re: Readonly Combobox - is this OK

Posted: Mon Nov 30, 2009 9:12 pm
by tinman
Why not just use DisableGadget(#Who, #True) when you click on "Review" and DisableGadget(#Who, #False) when you click on "Restore"?

Re: Readonly Combobox - is this OK

Posted: Wed Dec 02, 2009 6:32 am
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

Re: Readonly Combobox - is this OK

Posted: Wed Dec 02, 2009 11:55 am
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...

Re: Readonly Combobox - is this OK

Posted: Wed Dec 02, 2009 12:44 pm
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.

Re: Readonly Combobox - is this OK

Posted: Fri Dec 04, 2009 2:02 am
by leodh
@ Shardik

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

thanks again

leo