none
Comparing Datatable Values With ListBox Values..

    Question

  • Hello All !

    1. Datatable - dt is filling datagridview on the form (dt is getting value from sql database).

    2. User is selecting values from datatgrid to a listbox on the form.

    3. Now I have written a manual referesh for every 30 seconds. Where the newly added values to the database table are filled into dt and then dt fills the datagridview. My requirement is - The values which are already there in the listbox shouldn't be there in the datagridview/dt. So I have written (But it doesnt seems to work) :- 

       For Each Row As DataRow In dt.Rows
                    For i As Integer = 0 To ListBox1.Items.Count - 1
                        If Not Row.Item(0).Contains(ListBox1.Items(i).Item) Then
                            dt2.Rows.Add(Row.ItemArray)
                        End If
                        i += 1
                    Next
                Next

    Tuesday, January 29, 2013 12:00 PM

Answers

  • Please try below code. hope it will resolve your problem.

    Private Sub getdata()
    	Dim dt As New DataTable()
    	Dim dt1 As New DataTable()
    	For Each item As DataRow In dt.Rows
    		For i As Integer = 0 To listBox1.Items.Count - 1
    			If Convert.ToString(item("name")) <> Convert.ToString(listBox1.Items(i)) Then
    				dt1.Rows.Add(item)
    			End If
    		Next
    	Next
    	dt1.AcceptChanges()
    End Sub


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful". CRMHUNT http://crmhunt.com

    • Proposed as answer by CRM HUNT Tuesday, January 29, 2013 4:28 PM
    • Marked as answer by Youen ZenModerator Tuesday, February 5, 2013 8:46 AM
    Tuesday, January 29, 2013 4:28 PM