How Do I Use .NET Choice Controls (Magic xpa 4.x)
You can bind data to the control using the control’s Data property, exactly as you use Magic xpa built-in controls. (See: How Do I Bind Data to a .NET Control?).
However, as for the internal choice controls, the .NET choice controls also expect to get the items list (also known as the data source object).
You can either do this using .NET commands through the .NET object reference variable or by setting the Magic xpa properties as you do for the internal choice controls.
This topic is about using the Magic xpa properties to define the data source of the .NET control.
Since .NET controls have many properties, you will need to define which .NET property will get the data source and which properties will hold the value and display member names.
This definition is done at the model level in the DataSource Property Name, Display Member Property Name and Value Member Changed Event Name properties.
You will now add the .NET data source declarations to your .NET control model.
This definition can be done once per each control type for which you want to set data.
-
Create a model with GUI Display or Rich Client Display Class and set its Attribute to .NET.
-
Open the property sheet of the model and define an Object Type, such as System.Windows.Forms.ComboBox.
Note that you can use the auto-complete feature by pressing Ctrl+Space and whenever you insert a dot, a selection list with the available options will be opened (just like when you select a Magic xpa internal function).
-
Set the Value Property Name property to the property that will be bound to the data variable, such as SelectedValue.
-
Set the Value Changed Event Name property to the event that will be the trigger for updating back the data variable, such as SelectedValueChanged.
-
Set the DataSource Property Name property to the property that will receive the item list, such as DataSource.
-
Set the Display Member Property Name property to the property that defines the name of the column to be displayed, such as DisplayMember.
-
Set the Value Member Property Name property to the property that defines the name of the column that has the data, such as ValueMember.
That’s it, now the model can be used in your programs.
You will now use the .NET control model in your program.
-
Create a new program.
-
Create a variable in this program. This variable will be used to get/set the control’s data.
-
Zoom into the form and put a .NET control on the form.
-
Assign the new model to the .NET control.
Note that only models whose object type inherits from System.Windows.Forms.Control can be used for .NET controls on a form.
-
Assign the variable you created to the Data property.
-
Set the choice properties (such as item list and display list) of the control as you do for any internal choice control.
That’s it; you can now run the program and see that the item list is seen on the .NET control, that any change in the data variable is seen on the control, and any change in the control is updated to the data variable.
Since version: 2.3
The Online and Rich Client Samples projects (program NE13 and RNE13)