none
how to loop through a combo filled previously with a DataSet RRS feed

  • Question

  • hi all of you,

    I have filled one combobox from a XML file but it does contains a lot of duplicates.

    So that I am trying to remove all of them but I cannot due to is a binded control..

    My goal now is tranfer all the items for this databinding comobobox to another one and once there I will apply two FOR sentences in order to remove all the duplicates.

    Issues come when I try to move all the items to the other combobox:

                Me.cboAlternativo.Items.Add(Me.cboCategoria.Items(n))

    it doesn't work at all, it does transfer: System.Data.DataRowView

    1)LOAD XML INTO DATAGRIDVIEW AND COMBOBOX

             Dim ds As New DataSet
            ds.ReadXml(My.Application.Info.DirectoryPath & "\ProductAffiliatesFeed.xml")
            Me.DataGridView1.DataSource = ds.Tables(0)
            Me.cboCategoria.DataSource = ds.Tables(0)
            Me.cboCategoria.DisplayMember = "Category"
            Me.cboCategoria.ValueMember = "Product_id"

    2)REMOVE ALL THE DUPLICATES IN MY COMBOBOX

       Dim iCnt As Integer
            Dim jCnt As Integer
            Dim n, i As Integer

            For i = 0 To Me.cboCategoria.Items.Count - 1
                Me.cboAlternativo.Items.Add(Me.cboCategoria.Items(n))

            Next

      For iCnt = 0 To Me.cboAlternativo.Items.Count - 2
                For jCnt = Me.cboAlternativo.Items.Count - 1 To iCnt + 1 Step -1
                    If Me.cboAlternativo.Items(iCnt).ToString = Me.cboAlternativo.Items(jCnt).ToString Then
                        Me.cboAlternativo.Items.RemoveAt(jCnt)
                    End If
                Next
      Next


    Enric

    Monday, June 4, 2012 12:17 PM

Answers

All replies

  • Solved. Just using a Datatable object and FOR..EACH statement:

    Enric

    • Proposed as answer by Adavesh Monday, June 4, 2012 1:29 PM
    • Marked as answer by Mike FengModerator Tuesday, June 5, 2012 4:27 AM
    Monday, June 4, 2012 1:23 PM
  • Hi Enric,

    Thank you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 5, 2012 4:28 AM
    Moderator