Kbase P174667: Key-Value example for Microsoft Combobox .NET fails when converted to ABL
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  12/10/2010 |
|
Status: Unverified
SYMPTOM(s):
Key-Value example for Microsoft Combobox .NET fails when converted to ABL
Using example provided on MSDN converted from ListControl to Combobox:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listcontrol(v=VS.90).aspx
DisplayMember Property of the Combobox is empty if set before the DataSource Property of the Combobox
Error occurs when setting DisplayMember Property of the Combobox after setting the DataSource Property of the Combobox
Cannot bind to the new display member.
Parameter name: newDisplayMember
Querying the SelectedValue property of the Combobox should return the value of the property specified by ValueMember Property but in fact returns the value of the DisplayMember Property
FACT(s) (Environment):
Example uses System.Collections.ArrayList as the DataSource for the Combobox
MyArrayList = NEW System.Collections.ArrayList().
Key-Value pairing are generated by setting Properties of a separate class and add the class to the ArrayList
MyArrayList:Add(NEW ValText (1, "Text 1")).
MyArrayList:Add(NEW ValText (2, "Text 2")).
Separate class inherits from System.Object
CLASS ValText INHERITS System.Object:
DEFINE VARIABLE miValue AS INTEGER NO-UNDO.
DEFINE VARIABLE mcText AS CHARACTER NO-UNDO.
CONSTRUCTOR PUBLIC ValText ( INPUT piValue AS INT, INPUT pcText AS CHAR ):
miValue = piValue.
mcText = pcText.
END CONSTRUCTOR.
METHOD OVERRIDE PUBLIC CHARACTER ToString( ):
RETURN mcText.
END METHOD.
DEFINE PUBLIC PROPERTY MyValue AS INTEGER NO-UNDO
GET ():
RETURN miValue.
END GET.
DEFINE PUBLIC PROPERTY MyText AS CHARACTER NO-UNDO
GET ():
RETURN mcText.
END GET.
END CLASS.
DisplayMember and ValueMember Properties of the Combobox are set to the names of the class Properties representing the Key and Value settings
comboBox1:DisplayMember = "MyKey".
comboBox1:ValueMember = "MyValue".
OpenEdge 10.2x
Windows
CAUSE:
The main problem is the use of an ABL class that inherits from System.Object as the DataSource for the .NET Combobox. The two properties MyKey and MyValue are strictly ABL Properties. They are not part of an implementation of a .NET interface. There is no way for any .NET class to know they exist. They are not in the .NET part of the object that the AVM creates when it creates this "hybrid" .NET/ABL object. There is also no way for .NET to know these properties exist by using reflection which is likely what happens when setting the DisplayMember and ValueMember Properties.
FIX:
Option #1
Use a .NET object as the DataSource for the Combobox. The following code snippet demonstrates the use of a .NET Dictionary object to store the data:
msdict = NEW "System.Collections.Generic.Dictionary<integer, character>"().
msdict:Add(1, "Text 1").
msdict:Add(2, "Text 2").
msdict:Add(3, "Text 3").
msdict:Add(4, "Text 4").
comboBox1:DisplayMember = "Value".
comboBox1:ValueMember = "Key".
comboBox1:DataSource = NEW System.Windows.Forms.BindingSource(msdict,"").
Option #2
Use the ABL ProBindingSource as the DataSource for the Combobox. A temp-table can be used to store data.