Dataset & ListBox!

ebahammed

Member
Joined
Jul 21, 2003
Messages
13
Location
USA
Hello,
I have a dataset returned by a webservice. dataset has brNum and brName. How do I display both fields in the dataset as brNum-brName in a listBox ?

I want user to see both fields separated by a hyphen, inside a listbox.
Example: Albany-032
Somebody help me. Thanks in advance.
 
You can add them manually (to an ArrayList for example) and bind, or just fill the ListBox manually. Or you could create an expression column with both fields plus the hyphen and bind to that.

-Nerseus
 
Thanks Nerseus!
How do I create an expression? See, the data comes in as dataset to listbox. Also, I need to take what the user selected from the listbox.
Need help!
Thanks again.
 
You will have a separate column in your DataTable and set its type to string (in your case) and set the Expression property to something like:
ds.Tables[0].Columns[0].Expression = "brNum + - + brName";

If the brNum or brName fields might be null you can wrap them with IsNull(brNum, ) to convert to empty string. Check out the expression property in the help for Visual Studio. There is a LOT of stuff you can do with them.

Theres one weird problem with expressions. If you happen to define your DataSets using XSDs and the XSD has an expression column, the expression may not contain any data after you first call dataAdapter.Fill(). What weve seen is that setting the expression to itself will fix this, so in the above use something like:
ds.Tables[0].Columns[0].Expression = ds.Tables[0].Columns[0].Expression;

-Ner
 
Hello Nerseus,
I solved the above problem with the following code! It works well, but I have a new small task to do. And I am not sure how?

I need 1 row selected as default when page loads. How do I that with the way I added items into listbox from a dataset thats returned by a webservice?
As you have noticed, I am new programming, specially in vb.net!
Thank You.



Dim myService2 As New localhost1.Service1
Dim dsMyList As New DataSet


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


dsMyList = myService2.GetList()

Get the one table from the dsGetBranchList.
Dim myDataTable2 As DataTable = dsMyList.Tables(0)
For each row in the Table, display the info.
Dim temprow2 As DataRow
For Each temprow2 In myDataTable2.Rows
lstBranch.Items.Add((temprow2("LongName")) & " - " & (temprow2("Branch")))
Next
 
Back
Top