2 Replies - 2384 Views - Last Post: 16 August 2012 - 08:40 AM Rate Topic: -----

#1 Bladewing51  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 78
  • Joined: 26-August 11

WPF, Adding multi-column Dataset items to listboxes, NO BINDING

Posted 15 August 2012 - 02:54 PM

So I've been trying for the last two weeks to find an ideal way to take items from my database, (3 columns = Itemname, ItemNum, Price) and put them into a listbox which the user can then use to select the item/s he wants and move it over to listbox2 for further processing.

Now I'm doing this WITHOUT databinding the dataset to the listbox, although it was very simple and displayed everything perfectly with templates it resulted in some major headaches in the fact that you seem to lose alot of control over the databound itemcontrol E.g You cant remove an item from listbox1 after it is added to listbox2 without errors while using itemsource etc...

After much thought and research I've come up with the following...

Using a for each loop I'm copying the data from the dataset and adding that into the Items collection of the listbox itself. Its a simple solution that seems to give me less headaches and seems more inline with what I need for the program.

Now to my problem...

When I use the code below it seems to only show "Sytem.data.datarow" in the listbox (I'm guessing its because that row is holding 3 columns and the listbox doesnt know how to display it correctly.

        Dim i As Integer = 0

        Dim datarow As DataRow
        For Each datarow In ds.Tables(0).Rows
            lbox1.Items.Add(ds.Tables(0).Rows(i).ToString)
            i += 1
        Next




The only way I can get it to partially work is by specifically calling an item index to dispay instead as in the code below but I need all 3 columns to show in my listbox, not just the ItemNames.

        Dim i As Integer = 0

        Dim datarow As DataRow
        For Each datarow In ds.Tables(0).Rows
            lbox1.Items.Add(ds.Tables(0).Rows(i).Item(0).ToString)
            i += 1
        Next



So my question is this how can I programatically move all my dataset info into my listbox without binding, I am also planning on using item templates to show the 3 column data in a custom way as i did before when I was binding to the dataset, but I need the dataset content in my listbox first.

Thanks for your help in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: WPF, Adding multi-column Dataset items to listboxes, NO BINDING

#2 b2.f2  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 76
  • Joined: 21-May 07

Re: WPF, Adding multi-column Dataset items to listboxes, NO BINDING

Posted 16 August 2012 - 02:30 AM

 Dim datarow As DataRow
        For Each datarow In ds.Tables("tablename").Rows

            lbox1.Items.Add(datarow.Item("column1").ToString & "-" & datarow.Item("column2").ToString & "-" & datarow.Item("column3").ToString)

        Next


The above code gets rows from specified column name and added in listbox.

I recommend you to check out the datarow class Datarow class

This post has been edited by b2.f2: 16 August 2012 - 02:33 AM

Was This Post Helpful? 0
  • +
  • -

#3 Bladewing51  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 78
  • Joined: 26-August 11

Re: WPF, Adding multi-column Dataset items to listboxes, NO BINDING

Posted 16 August 2012 - 08:40 AM

That worked great thanks, now I can use templates to filter the data for readability onthe listbox. I've looked over all the itemscontrol and the data classes pretty well this last few weeks trying to learn more, but it just never occured to me to concantanate the code in that way, guess some times you just need a second pair of eyes.

Much appriciated.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1