fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Windows Forms ComboBox

Windows Forms ComboBox 11 months 3 weeks ago #1

  • leighproman
  • leighproman's Avatar Topic Author
  • Offline
  • Posts: 8
Have started converting some VO forms to Windows Forms and am having trouble with ComboBox.

Could someone point me to an example of how to set values for ComboBox items?
(equivalent of myComboBox:AddItem(name,0,value) or myComboBox:FillUsing({name,value}) in VO)

Thanks

Leigh

Please Log in or Create an account to join the conversation.

Windows Forms ComboBox 11 months 3 weeks ago #2

  • Phil Hepburn
  • Phil Hepburn's Avatar
  • Offline
  • Posts: 737
  • Karma: 7
Hi Leigh,

Try the method shown in the images - I did these last week for my printing stuff.





Cheers and Good Luck,
Phil.
Attachments:

Please Log in or Create an account to join the conversation.

Windows Forms ComboBox 11 months 3 weeks ago #3

Hi Leigh,

The ComboBox/ListBox in .Net does not have the context of separate "value" properties, but the items can encapsulate the values themselves. You are not restricted on adding strings, you can add instances of any kind of type as items and the control will show their ToString() representation. For example you can create a class
CLASS ListItem
	PROTECT _oValue AS OBJECT
	PROTECT _cText AS STRING
	CONSTRUCTOR(cText AS STRING , oValue AS OBJECT)
		SELF:_cText := cText
		SELF:_oValue := oValue
	RETURN
	PROPERTY @@Value AS OBJECT GET SELF:_oValue
	OVERRIDE METHOD ToString() AS STRING
	RETURN SELF:_cText
END CLASS

and add items with combo:Items:Add(ListItem{"string rep" , anyvalue}). When you want to read the "value" of the combobox, get the selected item, cast it to ListItem and get the "Value" property.

Of course you can also create your own ComboBox some class which encapsulates the above and makes it work in a similar way with the ComboBox in VO.

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

Windows Forms ComboBox 11 months 3 weeks ago #4

  • leighproman
  • leighproman's Avatar Topic Author
  • Offline
  • Posts: 8
Thanks for the help - all working now.

Leigh

Please Log in or Create an account to join the conversation.

Windows Forms ComboBox 11 months 3 weeks ago #5

  • Phil Hepburn
  • Phil Hepburn's Avatar
  • Offline
  • Posts: 737
  • Karma: 7
Hi Chris,

While we are on this subject, can you please inform / enlighten me as to why I had to make some code changes from a working older Vulcan version of an app.

In the Vulcan version the code was <int>{1,2,3 etc.} and also <double>{....} for the Zoom code line.

This would not compile / work ? for me and I had to adjust the code to <object> and then cast the selected item.

Should this be the case - what was different from the old code version I was copying ?

Once I got it up and running I just got on with Printing and Reports, and forgot to ask you or to feed back.

Any ideas for me ?
Cheers,
Phil.

Please Log in or Create an account to join the conversation.

Windows Forms ComboBox 11 months 3 weeks ago #6

Hi Phil,

Do you mean you needed that when you used AddRange()? This method accepts a parameter of type object[], this is why you got an error. c# reports the same error, apparently Vulcan allowed it, not sure if it was accidental or intentional, but I suspect it was accidental.

Even if you could get away with compiling it with int[], the combobox class still holds its items as objects, so you'd need the cast to int anyway. Or are you talking about WPF and there the combobox class is different?

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

Windows Forms ComboBox 11 months 3 weeks ago #7

  • Phil Hepburn
  • Phil Hepburn's Avatar
  • Offline
  • Posts: 737
  • Karma: 7
Hi Chris,

You seem to have it right - its WinForms stuff not WPF. The WPF example came after the one I simply converted from the past work I had done. The print Preview tools are both WinForm technology.

It looks like Vulcan did something a bit different, and as you say, we need to cast back the other way anyhow. So no big deal - except that the code failed first off.

I just thought in the spirit of 'community' that I needed to let you know what I found out.

Anyway, since I posted this info I had a VERY serious Windows 10 update, or new driver issue. The blue / green screens of death, happened in a 'blink', and no matter what I tried I could not get a reboot with any safety option - it just went around and around in a cycle ;-0((

Anyway, after a whole day and an evening I removed the boot device and have rebuilt my system without needing to start with a fresh Windows install (thank God) - and as you can see I can now post from Vivaldi.

The good news is that I now have both a working VS 2015 and the latest VS 2017 up and running, and with X# 1.2 as well. My Printing and Reporting apps run correctly as well - phew!

Needless to say that my Cologne material for sessions etc., is safely spread around - here, there, and everywhere. Also a BIG thanks to 'OneDrive' has to be said. What did we do before SkyDrive - now OneDrive ?

I have read the posted news regarding Grafxsoft and feel that it seems like an honest and fair statement of how things appeared to me.

It is also nice to get back more fully to a sense of 'community' and us all trying to help each other.

So onward and upwards :cheer:;)

I will try and do my bit to contribute and support.

Best regards,
Phil.
Wales, UK.

Please Log in or Create an account to join the conversation.

Windows Forms ComboBox 11 months 3 weeks ago #8

Hi Phil,

Yes, of coure, it's very good that you reported this! I just explained that this was probably a small bug of vulcan that had allowed it to compile in the first place.

About MS, Windows and its Updates, I think I'd better not comment, you said it all :)

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

  • Page:
  • 1