combobox
-
- Posts: 20
- Joined: Mon Feb 29, 2016 3:51 pm
- Location: Nicaragua
combobox
Is it possible to get an example of creation and use of a combobox with items type keyvaluepair in a winform in x#?
Re: combobox
Hi Giorgio,
if you are using an object as element to fill a ComboBox in Windows Forms, the following code should work:
where "PassSys" is the ComboBox, "oDict" the dictionary and "oItem" the current dataitem (or model, in case you are thinking in MVVM).
This is standard Windows Forms behavior.
Wolfgang
if you are using an object as element to fill a ComboBox in Windows Forms, the following code should work:
Code: Select all
self:PassSys:DisplayMember := "Value"
self:PassSys:ValueMember := "Key"
self:PassSys:DataSource := oDict
self:PassSys:SelectedValue := oItem:PassSys
This is standard Windows Forms behavior.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
-
- Posts: 20
- Joined: Mon Feb 29, 2016 3:51 pm
- Location: Nicaragua
Re: combobox
Thank Wolfgang,
my problem is to translate from c# to x# the following code:
comboBox1.Items.Add(new KeyValuePair<string, int>("Opción 1", 1));
comboBox1.Items.Add(new KeyValuePair<string, int>("Opción 2", 2));
comboBox1.Items.Add(new KeyValuePair<string, int>("Opción 3", 3));
getting values from the array:
aTab:={}
aadd(aTab,{"giorgio",123})
aadd(aTab,{"Jose",234})
TIA
Giorgio
my problem is to translate from c# to x# the following code:
comboBox1.Items.Add(new KeyValuePair<string, int>("Opción 1", 1));
comboBox1.Items.Add(new KeyValuePair<string, int>("Opción 2", 2));
comboBox1.Items.Add(new KeyValuePair<string, int>("Opción 3", 3));
getting values from the array:
aTab:={}
aadd(aTab,{"giorgio",123})
aadd(aTab,{"Jose",234})
TIA
Giorgio
Re: combobox
Hi Giorgio,
please forget the comboBox1.Items.Add syntax.
You can use every object to fill your combobox, just fill the correct values to the DisplayMember and ValueMember properties.
Wolfgang
please forget the comboBox1.Items.Add syntax.
Code: Select all
using System.Collections.Generic
local oValues as List<KeyValuePair<int,string>>
oValues := List<KeyValuePair<int,string>>{}
oValues:Add( 123, "giorgio" )
oValues:Add( 234 "jose" )
comboBox1:DisplayMember := "value"
comboBox1:ValueMember := "key"
comboBox1:DataSource := oValues
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Re: combobox
Giorgio,
I agree with Wolfgang, his suggested way to do it is much more elegant. But just for completeness, the direct translation of your c# code to X# is this:
ngpollarolo wrote: ↑Wed Dec 06, 2023 5:52 pm my problem is to translate from c# to x# the following code:
comboBox1.Items.Add(new KeyValuePair<string, int>("Opción 1", 1));
I agree with Wolfgang, his suggested way to do it is much more elegant. But just for completeness, the direct translation of your c# code to X# is this:
Code: Select all
comboBox1:Items:Add(KeyValuePair<STRING, INT>{"Opción 1", 1})
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu