Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. For and next loop... problem

For and next loop... problem

Scheduled Pinned Locked Moved C#
databasehelpquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    smguc
    wrote on last edited by
    #1

    Hi, I am trying to insert selected items from a listbox into a label, the listbox is fillby a database query, the problem is all I get is this System.Data.DataRowView it works fine when I dont use a database query and just text in the listbox. Cant anyone help on a solution for this?? Dim i As Integer For i = 0 To ListBoxUpgrade.Items.Count - 1 If ListBoxUpgrade.Items(i) Then LabelSum.Text = LabelSum.Text & Space(6) & ListBoxUpgrade.SelectedItem(i) & vbCrLf End If Next i Thanks in advance! Stefan.

    "All answers have a question? All code has an end."

    V C V 3 Replies Last reply
    0
    • S smguc

      Hi, I am trying to insert selected items from a listbox into a label, the listbox is fillby a database query, the problem is all I get is this System.Data.DataRowView it works fine when I dont use a database query and just text in the listbox. Cant anyone help on a solution for this?? Dim i As Integer For i = 0 To ListBoxUpgrade.Items.Count - 1 If ListBoxUpgrade.Items(i) Then LabelSum.Text = LabelSum.Text & Space(6) & ListBoxUpgrade.SelectedItem(i) & vbCrLf End If Next i Thanks in advance! Stefan.

      "All answers have a question? All code has an end."

      V Offline
      V Offline
      valerian precop
      wrote on last edited by
      #2

      I don't use VB very much but from what I know in C# if you use something like ListBox1.SelectedItem[i] it would not work. ListBox1.SelectedItem[i] returns a ListItem this one has a Text and a Value property. I think you should use something like ListBoxUpgrade.SelectedItem(i).Text Hope it helps...

      Just call me Valy... :)

      1 Reply Last reply
      0
      • S smguc

        Hi, I am trying to insert selected items from a listbox into a label, the listbox is fillby a database query, the problem is all I get is this System.Data.DataRowView it works fine when I dont use a database query and just text in the listbox. Cant anyone help on a solution for this?? Dim i As Integer For i = 0 To ListBoxUpgrade.Items.Count - 1 If ListBoxUpgrade.Items(i) Then LabelSum.Text = LabelSum.Text & Space(6) & ListBoxUpgrade.SelectedItem(i) & vbCrLf End If Next i Thanks in advance! Stefan.

        "All answers have a question? All code has an end."

        C Offline
        C Offline
        Corinna John
        wrote on last edited by
        #3

        You must select a column index for the DataRowView. Try this: for(int i=0; i<ListBoxUpgrade.Items.Count-1; i++) { if(ListBoxUpgrade.Items[i].IsSelected) { LabelSum.Text += " " + ((DataRowView)ListBoxUpgrade.SelectedItem[i])[yourIndex] + "\r\n"; } }

        ____________________________________ There is no proof for this sentence.

        1 Reply Last reply
        0
        • S smguc

          Hi, I am trying to insert selected items from a listbox into a label, the listbox is fillby a database query, the problem is all I get is this System.Data.DataRowView it works fine when I dont use a database query and just text in the listbox. Cant anyone help on a solution for this?? Dim i As Integer For i = 0 To ListBoxUpgrade.Items.Count - 1 If ListBoxUpgrade.Items(i) Then LabelSum.Text = LabelSum.Text & Space(6) & ListBoxUpgrade.SelectedItem(i) & vbCrLf End If Next i Thanks in advance! Stefan.

          "All answers have a question? All code has an end."

          V Offline
          V Offline
          V 0
          wrote on last edited by
          #4

          you would be better of posting this in the VB forum instead of the C# forum...:)

          S 1 Reply Last reply
          0
          • V V 0

            you would be better of posting this in the VB forum instead of the C# forum...:)

            S Offline
            S Offline
            smguc
            wrote on last edited by
            #5

            Thanks, Sorry I thought I had! My bad.

            "All answers have a question? All code has an end."

            V 1 Reply Last reply
            0
            • S smguc

              Thanks, Sorry I thought I had! My bad.

              "All answers have a question? All code has an end."

              V Offline
              V Offline
              V 0
              wrote on last edited by
              #6

              no worries, if you browse long enough trhough CP you can tell the difference between people making a mistake and people just being lazy :-). There is no bad in making a mistake, it makes us human ;-).

              V.
              Stop smoking so you can: Enjoy longer the money you save. Moviereview Archive

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups