3 Replies - 719 Views - Last Post: 06 December 2012 - 07:41 AM Rate Topic: -----

#1 Bladewing51  Icon User is offline

  • D.I.C Head

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

Multiple data from list into multiple controls using loops, WPF

Posted 05 December 2012 - 02:32 PM

I have a grid of 3 X 5 controls that I have pieced together using 2 labels inside a canvas.

What I'm attempting to do is take data from my generic list (Which has 3 columns DescL, PriceL, BarcodeL) and disseminate the data like so...

A Description into label1
A Price to label2
the barcode to variable

I'm currently using a for each loop to get the data out of the list and into its correct controls. See Below...

        Dim i As Integer = 0
        For Each list In lists
            barcode = lists.Item(i).barcodeL
            barcode_Lbl_Desc1.Content = lists.Item(i).descL
             barcodes_Lbl_Price1.Content = (lists.Item(i).priceL.ToString("C2"))
            i = i + 1
        Next



But as you can probably see from this there is no way to increment the control names with a variable in a for each loop to make it move to the next numbered labels in the sequence. I'm toying with the idea of making a user control almost like a listbox that would create a new smaller user controls inside it that has the labels and control in the right position for each item in the list. Although I have no idea how I would build such a control.

My question is what have other people done in this situation.
Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Multiple data from list into multiple controls using loops, WPF

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5595
  • View blog
  • Posts: 11,971
  • Joined: 02-June 10

Re: Multiple data from list into multiple controls using loops, WPF

Posted 05 December 2012 - 02:53 PM

Quote

using 2 labels inside a canvas.
[...]
move to the next numbered labels in the sequence.


Yeah... you really need to get away from that kind of thinking. You want to use a DataGrid. It will keep adding rows as you keep adding information.

http://www.codeproje...ctical-Examples

http://wpftutorial.net/DataGrid.html
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: Multiple data from list into multiple controls using loops, WPF

Posted 05 December 2012 - 09:42 PM

I dont think a control like that will really work for me, I was keeping things simple for the question but what my program does is takes the barcode numbers and draws the actual barcode onto the canvas. A label above and below provides the description and price whilst 4 other labels seperate the actual barcode number into its standard format.

Example. Country code number outside of barcode, manufacturers number inside and under etc...

There HAS to be a way if a datagrid or listbox already does this, right?
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5595
  • View blog
  • Posts: 11,971
  • Joined: 02-June 10

Re: Multiple data from list into multiple controls using loops, WPF

Posted 06 December 2012 - 07:41 AM

You could make a UserControl that has the textbox, picturebox and so on. You give it an object with the information, it fills the GUI controls. If you have 10 objects, you make 10 UserControls.

This article does some good example of what I'm talking about. It was written for WinForms but its the exact same concept for WPF.
http://www.dreaminco...ister-part-one/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1