This is a migrated thread and some comments may be shown as answers.

How to set up 2 dimensional array as source for parameter

3 Answers 41 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ed Lance
Top achievements
Rank 1
Ed Lance asked on 11 May 2012, 12:58 AM
I've used code behind to set up an array to supply values for a dropdown parameter.  This works fine if the Display Member and Value Member are the same.  But now I have a scenario where I want to have a dropdown where the display shows text and the value is an integer.  There are only a few values so I didn't think I would need to create a SQL table for them, but I haven't got this to work yet.

Here is the code:
Public Sub New()
    InitializeComponent()
 
    Dim aryorder(,) As String = {{0, "Lot"}, {1, "Address"}}
 
    Me.ReportParameters("Order").AvailableValues.DataSource = aryorder
 
 
End Sub

This works, but I can't figure out what to set for the DisplayMember property.  I can use =Fields.Item to get the number for the ValueMember, but I don't know what to use for the DisplayMember.  Any ideas?

Thanks

3 Answers, 1 is accepted

Sort by
0
Hadib Ahmabi
Top achievements
Rank 1
answered on 11 May 2012, 10:00 AM
How about creating a  structure or a class and assigning a list of objects? 
Public Class ParamClass
Public Property Name() As String
...
Public Property Value() As Integer
...
End Class
0
Ed Lance
Top achievements
Rank 1
answered on 11 May 2012, 06:40 PM

I made a class like that but still couldn't figure out what to set for the DisplayMember and ValueMember property.
Then I tried a hashtable and that seemed to work much better.  My only beef with this is that it seems to sort the dropdown list by DisplayMember even though I did not specify a sort in the AvailableValues.

With this code, DisplayMember = value and ValueMember = key  (these are the properties of the hashtable)

Public Sub New()
    InitializeComponent()
 
    Dim ht As New Hashtable
 
    ht.Add("0", "Lot")
    ht.Add("1", "Address")
 
 
    Me.ReportParameters("Order").AvailableValues.DataSource = ht
 
End Sub

This really needs to be improved.  SSRS 2008 has a GUI where you can manually enter values for a dropdown without having to resort to code.

0
Ed Lance
Top achievements
Rank 1
answered on 12 May 2012, 01:58 AM
Well today the mysterious sorting went away, so looks like hashtable is the winner for this issue.
Tags
General Discussions
Asked by
Ed Lance
Top achievements
Rank 1
Answers by
Hadib Ahmabi
Top achievements
Rank 1
Ed Lance
Top achievements
Rank 1
Share this question
or