DataBindings for a LookupBox

Stimulsoft Reports.NET discussion
Post Reply
scotty
Posts: 28
Joined: Tue Jul 04, 2006 2:05 am
Location: Austria

DataBindings for a LookupBox

Post by scotty »

How do I set the DataBindings for a LookupBox?

I want to see the datafield "label" in the lookupBox and get the datafield "id" for the selected value
my query looks like "select * from [Enumeration-View]"

Is there an example?

I am using version 2006.4

Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

DataBindings for a LookupBox

Post by Brendan »

Are you talking about a ComboBox on a Form?

If you you can access the underlying control using the "Control" property.

for example, if you have a comboBox1 control on the form you can set the datasource to a DataTable

comboBox1.Control.DisplayMember = "label";
comboBox1.Control.ValueMember = "id";
comboBox1.Control.Datasource = myData;

scotty
Posts: 28
Joined: Tue Jul 04, 2006 2:05 am
Location: Austria

DataBindings for a LookupBox

Post by scotty »

Thanks for your answer!

I have a Form in my Report with a LookupBox. I want to display there values from a datasource from the dictionary called Enumeration. This DataSource get the values from the database with a sql query ("Select * from [Enumeration-View]"). In the LookupBox I want display values from the datafield called "label" with underlying datafield "id".

In the properties of the LookupBox I set the databindings for Text to datafield "label" and for Keys to datafield "id".

When I render the report to the preview-window the Form comes up but the LookupBox does not display any values/rows.

Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

DataBindings for a LookupBox

Post by Brendan »

Hi Scotty,
If you have already registered a Datasource to the Dictionary then in your FormLoad code in the stimulReport Form you can try this:


ComboBoxControl1.Control.DisplayMember = "label";
ComboBoxControl1.Control.ValueMember = "id";
ComboBoxControl1.Control.DataSource = this.Dictionary.DataSources["Enumeration"].DataTable;

where:
ComboBoxControl1 is the name of your LookupBox
and this.Dictionary.DataSources["Enumeration"] is the name of your DataSource in the dictionary.

Regards,
Brendan.
scotty
Posts: 28
Joined: Tue Jul 04, 2006 2:05 am
Location: Austria

DataBindings for a LookupBox

Post by scotty »

Thanks

This works fine, now I see the all the values, but when i select one of the values in the lookupbox I get an error:

Method: [get_Item]
Der Index liegt außerhalb des gültigen Bereichs. Der Index darf keine negaitve Zahl und muss kleiner als die Auflistungsgröße sein.
Parametername: index.

in englisch:
Index out of range. index must be positive and less than the number of entries in the list
parameter: index

Please help
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

DataBindings for a LookupBox

Post by Edward »

And you also may use a LookUpBoxControl in the following way.

Please set lookUpBox.Keys and lookUpBox.SelectedKey to the key value of your DataSource.
lookUpBox.Items should be set to the result value of your DataSource.

After that result of the user choice you may get in the following properties:

Result value - lookUpBox.SelectedItem
Key value - lookUpBox.SelectedKey

Thank you for the cooperation.
Post Reply