Results 1 to 27 of 27

Thread: This causes two bindings in the collection to bind to the same property vb.net

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    This causes two bindings in the collection to bind to the same property vb.net

    Dear All Master,
    I have a problem with binding. Please solution and I want expicturebox to appear if I click datagridview in cell ITC because if it immediately makes datagridview very slow.
    Note : I use visual studio 2010

    Code:
    Public Class Form1
        Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        Dim cn = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Path & "; Extended Properties=dBase IV"
        Private WithEvents dt As New DataTable
        Dim Pathimage As String = "C:\Users\ADMIN2\Desktop\CATALOG"
    Private Sub PopulateComboBox()
            Dim query As String = "SELECT DISTINCT SHI FROM IFG WHERE QOH > 0"
            Try
                Using con As OleDbConnection = New OleDbConnection(cn)
                    Using sda As OleDbDataAdapter = New OleDbDataAdapter(query, con)
                        'Fill the DataTable with records from Table.
                        Dim dt As DataTable = New DataTable()
                        sda.Fill(dt)
    
                        'Insert the Default Item to DataTable.
                        Dim row As DataRow = dt.NewRow()
    
                        row(0) = ""
                        dt.Rows.InsertAt(row, 0)
    
                        'Assign DataTable as DataSource.
                        ComboBox1.DataSource = dt
                        ComboBox1.DisplayMember = "SHI"
                        ComboBox1.ValueMember = "SHI"
                    End Using
                End Using
            Catch myerror As OleDbException
                MessageBox.Show("Error: " & myerror.Message)
            Finally
    
            End Try
        End Sub
     Private Sub DataGridView()
    
            Try
                dt = New DataTable
                Dim query = "select ITM,ITC,QOH,PRS,PRSOBBRT,PRSOBNET,FILENAME1,FILENAME2,FILENAME3,FILENAME4,FILENAME5,FILENAME6 FROM IFG WHERE QOH > 0 AND SHI = @SHI"
     Using con As OleDbConnection = New OleDbConnection(cn)
                    Using cmd As OleDbCommand = New OleDbCommand(query, con)
    
                        cmd.Parameters.AddWithValue("@SHI", ComboBox1.SelectedValue)
    
    
                        Using adapter As New OleDbDataAdapter(cmd)
                            'Dim dt As DataTable = New DataTable()
                            adapter.Fill(dt)
                            'Me.DataGridView1.DataSource = dt
    
                        End Using
                    End Using
                End Using
                Me.DataGridView1.DataSource = dt
                DataGridView1.RowHeadersWidth = 65
                DataGridView1.TopLeftHeaderCell.Value = "NO"
                DataGridView1.TopLeftHeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
     AddHandler Me.DataGridView1.RowPostPaint, AddressOf Me.dgvUserDetails_RowPostPaint
                For x As Integer = 6 To 11
                    Me.DataGridView1.Columns(x).Visible = False
                Next
                ExPictureBox1.PrePath = Pathimage & "\"
                ExPictureBox2.PrePath = Pathimage & "\"
                ExPictureBox3.PrePath = Pathimage & "\"
                ExPictureBox4.PrePath = Pathimage & "\"
                ExPictureBox5.PrePath = Pathimage & "\"
                ExPictureBox6.PrePath = Pathimage & "\"
    
                ExPictureBox1.DataBindings.Add("FileName", dt, "FILENAME1") ' problem This causes two bindings in the collection to bind to the same property
                ExPictureBox2.DataBindings.Add("FileName", dt, "FILENAME2")
                ExPictureBox3.DataBindings.Add("FileName", dt, "FILENAME3")
                ExPictureBox4.DataBindings.Add("FileName", dt, "FILENAME4")
                ExPictureBox5.DataBindings.Add("FileName", dt, "FILENAME5")
                ExPictureBox6.DataBindings.Add("FileName", dt, "FILENAME6")
    Catch myerror As OleDbException
                MessageBox.Show("Error: " & myerror.Message)
            Finally
                'cn.Dispose()
            End Try
        End Sub
    Thanks
    roy88
    Attached Images Attached Images  
    Last edited by roy88; Dec 29th, 2021 at 12:05 AM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,480

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Looks like you're querying your database and setting your bindings on ComboBox1_SelectedIndexChanged. That would cause an error. You should be using the Master Details pattern, with ComboBox1 being Master and DataGridView1 being Details. You would only be querying your database once...

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by .paul. View Post
    Looks like you're querying your database and setting your bindings on ComboBox1_SelectedIndexChanged. That would cause an error. You should be using the Master Details pattern, with ComboBox1 being Master and DataGridView1 being Details. You would only be querying your database once...
    Dear Mr. .paul. ,
    Thanks for your reply. What is the code solution if I query only once according to your answer?
    if I use the expicturebox binding to be very slow because the actual item is fifteen thousand maybe better expicturebox appears when clicking cell ITC column or there is another solution
    Thanks
    roy88

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,480

    Re: This causes two bindings in the collection to bind to the same property vb.net

    It's slow because you're querying every time you change your combobox item. Google Master Details

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by .paul. View Post
    It's slow because you're querying every time you change your combobox item. Google Master Details
    dear sir,
    Please guide me to create a detailed master as you conveyed.
    So it doesn't become slow.
    thanks
    roy88

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,480

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Try this...

    Code:
    Imports System.Data.OleDb
    
    Public Class Form17
        Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        Dim cn = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Path & "; Extended Properties=dBase IV"
        Private WithEvents dt As New DataTable
        Dim Pathimage As String = "C:\Users\ADMIN2\Desktop\CATALOG"
    
        Private Sub DataGridView()
    
            Try
                dt = New DataTable
                Dim query = "select SHI,ITM,ITC,QOH,PRS,PRSOBBRT,PRSOBNET,FILENAME1,FILENAME2,FILENAME3,FILENAME4,FILENAME5,FILENAME6 FROM IFG WHERE QOH > 0"
                Using con As OleDbConnection = New OleDbConnection(cn)
                    Using cmd As OleDbCommand = New OleDbCommand(query, con)
    
                        Using adapter As New OleDbDataAdapter(cmd)
                            'Dim dt As DataTable = New DataTable()
                            adapter.Fill(dt)
                            'Me.DataGridView1.DataSource = dt
    
                        End Using
                    End Using
                End Using
                Me.DataGridView1.DataSource = dt
                DataGridView1.RowHeadersWidth = 65
                DataGridView1.TopLeftHeaderCell.Value = "NO"
                DataGridView1.TopLeftHeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
                AddHandler Me.DataGridView1.RowPostPaint, AddressOf Me.dgvUserDetails_RowPostPaint
                For x As Integer = 6 To 11
                    Me.DataGridView1.Columns(x).Visible = False
                Next
                ExPictureBox1.PrePath = Pathimage & "\"
                ExPictureBox2.PrePath = Pathimage & "\"
                ExPictureBox3.PrePath = Pathimage & "\"
                ExPictureBox4.PrePath = Pathimage & "\"
                ExPictureBox5.PrePath = Pathimage & "\"
                ExPictureBox6.PrePath = Pathimage & "\"
    
                ExPictureBox1.DataBindings.Add("FileName", dt, "FILENAME1") ' problem This causes two bindings in the collection to bind to the same property
                ExPictureBox2.DataBindings.Add("FileName", dt, "FILENAME2")
                ExPictureBox3.DataBindings.Add("FileName", dt, "FILENAME3")
                ExPictureBox4.DataBindings.Add("FileName", dt, "FILENAME4")
                ExPictureBox5.DataBindings.Add("FileName", dt, "FILENAME5")
                ExPictureBox6.DataBindings.Add("FileName", dt, "FILENAME6")
            Catch myerror As OleDbException
                MessageBox.Show("Error: " & myerror.Message)
            Finally
                'cn.Dispose()
            End Try
        End Sub
    
        Private Sub Form17_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            DataGridView()
            Dim dtDistinct As DataTable = dt.DefaultView.ToTable(True, "SHI")
    
            'Insert the Default Item to DataTable.
            Dim row As DataRow = dtDistinct.NewRow()
    
            row(0) = ""
            dtDistinct.Rows.InsertAt(row, 0)
    
            'Assign DataTable as DataSource.
            ComboBox1.DataSource = dtDistinct
            ComboBox1.DisplayMember = "SHI"
            ComboBox1.ValueMember = "SHI"
        End Sub
    
    End Class

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by .paul. View Post
    Try this...

    Code:
    Imports System.Data.OleDb
    
    Public Class Form17
        Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        Dim cn = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Path & "; Extended Properties=dBase IV"
        Private WithEvents dt As New DataTable
        Dim Pathimage As String = "C:\Users\ADMIN2\Desktop\CATALOG"
    
        Private Sub DataGridView()
    
            Try
                dt = New DataTable
                Dim query = "select SHI,ITM,ITC,QOH,PRS,PRSOBBRT,PRSOBNET,FILENAME1,FILENAME2,FILENAME3,FILENAME4,FILENAME5,FILENAME6 FROM IFG WHERE QOH > 0"
                Using con As OleDbConnection = New OleDbConnection(cn)
                    Using cmd As OleDbCommand = New OleDbCommand(query, con)
    
                        Using adapter As New OleDbDataAdapter(cmd)
                            'Dim dt As DataTable = New DataTable()
                            adapter.Fill(dt)
                            'Me.DataGridView1.DataSource = dt
    
                        End Using
                    End Using
                End Using
                Me.DataGridView1.DataSource = dt
                DataGridView1.RowHeadersWidth = 65
                DataGridView1.TopLeftHeaderCell.Value = "NO"
                DataGridView1.TopLeftHeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
                AddHandler Me.DataGridView1.RowPostPaint, AddressOf Me.dgvUserDetails_RowPostPaint
                For x As Integer = 6 To 11
                    Me.DataGridView1.Columns(x).Visible = False
                Next
                ExPictureBox1.PrePath = Pathimage & "\"
                ExPictureBox2.PrePath = Pathimage & "\"
                ExPictureBox3.PrePath = Pathimage & "\"
                ExPictureBox4.PrePath = Pathimage & "\"
                ExPictureBox5.PrePath = Pathimage & "\"
                ExPictureBox6.PrePath = Pathimage & "\"
    
                ExPictureBox1.DataBindings.Add("FileName", dt, "FILENAME1") ' problem This causes two bindings in the collection to bind to the same property
                ExPictureBox2.DataBindings.Add("FileName", dt, "FILENAME2")
                ExPictureBox3.DataBindings.Add("FileName", dt, "FILENAME3")
                ExPictureBox4.DataBindings.Add("FileName", dt, "FILENAME4")
                ExPictureBox5.DataBindings.Add("FileName", dt, "FILENAME5")
                ExPictureBox6.DataBindings.Add("FileName", dt, "FILENAME6")
            Catch myerror As OleDbException
                MessageBox.Show("Error: " & myerror.Message)
            Finally
                'cn.Dispose()
            End Try
        End Sub
    
        Private Sub Form17_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            DataGridView()
            Dim dtDistinct As DataTable = dt.DefaultView.ToTable(True, "SHI")
    
            'Insert the Default Item to DataTable.
            Dim row As DataRow = dtDistinct.NewRow()
    
            row(0) = ""
            dtDistinct.Rows.InsertAt(row, 0)
    
            'Assign DataTable as DataSource.
            ComboBox1.DataSource = dtDistinct
            ComboBox1.DisplayMember = "SHI"
            ComboBox1.ValueMember = "SHI"
        End Sub
    
    End Class
    Dear Mr. Paul,
    Thanks for your reply. I tried to code from you no error.
    for combobox even though it has appeared but can not do filters and I try still slow to move from row datagridview and also for search to be slow. If I do comment code below then it runs normally. is there a solution so that ExPictureBox.DataBindings does not make datagridview slow?
    Code:
     'ExPictureBox1.PrePath = Pathimage & "\"
                'ExPictureBox2.PrePath = Pathimage & "\"
                'ExPictureBox3.PrePath = Pathimage & "\"
                'ExPictureBox4.PrePath = Pathimage & "\"
                'ExPictureBox5.PrePath = Pathimage & "\"
                'ExPictureBox6.PrePath = Pathimage & "\"
    
                'ExPictureBox1.DataBindings.Add("FileName", dt, "FILENAME1")
                'ExPictureBox2.DataBindings.Add("FileName", dt, "FILENAME2")
                'ExPictureBox3.DataBindings.Add("FileName", dt, "FILENAME3")
                'ExPictureBox4.DataBindings.Add("FileName", dt, "FILENAME4")
                'ExPictureBox5.DataBindings.Add("FileName", dt, "FILENAME5")
                'ExPictureBox6.DataBindings.Add("FileName", dt, "FILENAME6")
    This is the textbox code I use.
    Code:
    Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
     Try
                CType(DataGridView1.DataSource, DataTable).DefaultView.RowFilter = String.Format("ITM LIKE '%{0}%' OR ITM LIKE '%{0}%'", TextBox1.Text)
    Catch ex As Exception
                MsgBox("No match found")
            End Try
        End Sub

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,480

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Code:
    Imports System.Data.OleDb
    
    Public Class Form17
        Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        Dim cn = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Path & "; Extended Properties=dBase IV"
        Private WithEvents dt As New DataTable
        Dim bs As BindingSource
        Dim Pathimage As String = "C:\Users\ADMIN2\Desktop\CATALOG"
    
        Private Sub DataGridView()
    
            Try
                dt = New DataTable
                Dim query = "select SHI,ITM,ITC,QOH,PRS,PRSOBBRT,PRSOBNET,FILENAME1,FILENAME2,FILENAME3,FILENAME4,FILENAME5,FILENAME6 FROM IFG WHERE QOH > 0"
                Using con As OleDbConnection = New OleDbConnection(cn)
                    Using cmd As OleDbCommand = New OleDbCommand(query, con)
    
                        Using adapter As New OleDbDataAdapter(cmd)
                            'Dim dt As DataTable = New DataTable()
                            adapter.Fill(dt)
                            'Me.DataGridView1.DataSource = dt
    
                        End Using
                    End Using
                End Using
    
                bs = New BindingSource
                bs.DataSource = dt
                Me.DataGridView1.DataSource = bs
                DataGridView1.RowHeadersWidth = 65
                DataGridView1.TopLeftHeaderCell.Value = "NO"
                DataGridView1.TopLeftHeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
                AddHandler Me.DataGridView1.RowPostPaint, AddressOf Me.dgvUserDetails_RowPostPaint
                For x As Integer = 6 To 11
                    Me.DataGridView1.Columns(x).Visible = False
                Next
                ExPictureBox1.PrePath = Pathimage & "\"
                ExPictureBox2.PrePath = Pathimage & "\"
                ExPictureBox3.PrePath = Pathimage & "\"
                ExPictureBox4.PrePath = Pathimage & "\"
                ExPictureBox5.PrePath = Pathimage & "\"
                ExPictureBox6.PrePath = Pathimage & "\"
    
                ExPictureBox1.DataBindings.Add("FileName", bs, "FILENAME1") ' problem This causes two bindings in the collection to bind to the same property
                ExPictureBox2.DataBindings.Add("FileName", bs, "FILENAME2")
                ExPictureBox3.DataBindings.Add("FileName", bs, "FILENAME3")
                ExPictureBox4.DataBindings.Add("FileName", bs, "FILENAME4")
                ExPictureBox5.DataBindings.Add("FileName", bs, "FILENAME5")
                ExPictureBox6.DataBindings.Add("FileName", bs, "FILENAME6")
            Catch myerror As OleDbException
                MessageBox.Show("Error: " & myerror.Message)
            Finally
                'cn.Dispose()
            End Try
        End Sub
    
        Private Sub Form17_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            DataGridView()
            Dim dtDistinct As DataTable = dt.DefaultView.ToTable(True, "SHI")
    
            'Insert the Default Item to DataTable.
            Dim row As DataRow = dtDistinct.NewRow()
    
            row(0) = ""
            dtDistinct.Rows.InsertAt(row, 0)
    
            'Assign DataTable as DataSource.
            ComboBox1.DataSource = dtDistinct
            ComboBox1.DisplayMember = "SHI"
            ComboBox1.ValueMember = "SHI"
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            bs.Filter = "SHI = " & ComboBox1.Text
        End Sub
    
    End Class

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,480

    Re: This causes two bindings in the collection to bind to the same property vb.net

    I'm not sure why the ExPictureBox loading is slowing your application, except you have 6 of these for which the filename must be found on each row change and also 6 images you're loading...

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by .paul. View Post
    Code:
    Imports System.Data.OleDb
    
    Public Class Form17
        Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        Dim cn = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Path & "; Extended Properties=dBase IV"
        Private WithEvents dt As New DataTable
        Dim bs As BindingSource
        Dim Pathimage As String = "C:\Users\ADMIN2\Desktop\CATALOG"
    
        Private Sub DataGridView()
    
            Try
                dt = New DataTable
                Dim query = "select SHI,ITM,ITC,QOH,PRS,PRSOBBRT,PRSOBNET,FILENAME1,FILENAME2,FILENAME3,FILENAME4,FILENAME5,FILENAME6 FROM IFG WHERE QOH > 0"
                Using con As OleDbConnection = New OleDbConnection(cn)
                    Using cmd As OleDbCommand = New OleDbCommand(query, con)
    
                        Using adapter As New OleDbDataAdapter(cmd)
                            'Dim dt As DataTable = New DataTable()
                            adapter.Fill(dt)
                            'Me.DataGridView1.DataSource = dt
    
                        End Using
                    End Using
                End Using
    
                bs = New BindingSource
                bs.DataSource = dt
                Me.DataGridView1.DataSource = bs
                DataGridView1.RowHeadersWidth = 65
                DataGridView1.TopLeftHeaderCell.Value = "NO"
                DataGridView1.TopLeftHeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
                AddHandler Me.DataGridView1.RowPostPaint, AddressOf Me.dgvUserDetails_RowPostPaint
                For x As Integer = 6 To 11
                    Me.DataGridView1.Columns(x).Visible = False
                Next
                ExPictureBox1.PrePath = Pathimage & "\"
                ExPictureBox2.PrePath = Pathimage & "\"
                ExPictureBox3.PrePath = Pathimage & "\"
                ExPictureBox4.PrePath = Pathimage & "\"
                ExPictureBox5.PrePath = Pathimage & "\"
                ExPictureBox6.PrePath = Pathimage & "\"
    
                ExPictureBox1.DataBindings.Add("FileName", bs, "FILENAME1") ' problem This causes two bindings in the collection to bind to the same property
                ExPictureBox2.DataBindings.Add("FileName", bs, "FILENAME2")
                ExPictureBox3.DataBindings.Add("FileName", bs, "FILENAME3")
                ExPictureBox4.DataBindings.Add("FileName", bs, "FILENAME4")
                ExPictureBox5.DataBindings.Add("FileName", bs, "FILENAME5")
                ExPictureBox6.DataBindings.Add("FileName", bs, "FILENAME6")
            Catch myerror As OleDbException
                MessageBox.Show("Error: " & myerror.Message)
            Finally
                'cn.Dispose()
            End Try
        End Sub
    
        Private Sub Form17_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            DataGridView()
            Dim dtDistinct As DataTable = dt.DefaultView.ToTable(True, "SHI")
    
            'Insert the Default Item to DataTable.
            Dim row As DataRow = dtDistinct.NewRow()
    
            row(0) = ""
            dtDistinct.Rows.InsertAt(row, 0)
    
            'Assign DataTable as DataSource.
            ComboBox1.DataSource = dtDistinct
            ComboBox1.DisplayMember = "SHI"
            ComboBox1.ValueMember = "SHI"
        End Sub
    
        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            bs.Filter = "SHI = " & ComboBox1.Text
        End Sub
    
    End Class
    Thanks for your reply. there is a warning "Cannot find column [System.Data.DataRowView]." in the code below
    Code:
            bs.Filter = "SHI = " & ComboBox1.Text

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,480

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Check the Select Statement I used. Ensure that yours is the same

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by .paul. View Post
    I'm not sure why the ExPictureBox loading is slowing your application, except you have 6 of these for which the filename must be found on each row change and also 6 images you're loading...
    dear mr.Paul
    so 6 filenames are not all contained so there are some full from filename1 to filename6 and there is also contains only filename1 and there is also contains filename1 &filename2. what makes it slow because it directly loading from datagridview?.

    thanks
    roy88

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by .paul. View Post
    Check the Select Statement I used. Ensure that yours is the same
    Code:
    Dim query = "select SHI,ITM,ITC,QOH,PRS,PRSOBBRT,PRSOBNET,FILENAME1,FILENAME2,FILENAME3,FILENAME4,FILENAME5,FILENAME6 FROM IFG WHERE QOH > 0"
    It's the same as your sql statement.

  14. #14
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,480

    Re: This causes two bindings in the collection to bind to the same property vb.net

    The problem is that the code is attempting to set the filter before the BindingSource is initialised.

    Code:
    If bs Is Nothing Then Return
    bs.Filter = "SHI = " & ComboBox1.Text

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by .paul. View Post
    The problem is that the code is attempting to set the filter before the BindingSource is initialised.

    Code:
    If bs Is Nothing Then Return
    bs.Filter = "SHI = " & ComboBox1.Text
    there is still a warning "Cannot find column [System.Data.DataRowView]."
    Attached Images Attached Images  

  16. #16
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,480

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Code:
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If bs Is Nothing Then Return
        Dim drv As DataRowView = DirectCast(ComboBox1.SelectedItem, DataRowView)
        If drv.Item("SHI").ToString = "" Then bs.Filter = "SHI = '%'": Return
        bs.Filter = "SHI = '" & drv.Item("SHI").ToString & "'"
    End Sub

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by .paul. View Post
    Code:
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If bs Is Nothing Then Return
        Dim drv As DataRowView = DirectCast(ComboBox1.SelectedItem, DataRowView)
        If drv.Item("SHI").ToString = "" Then bs.Filter = "SHI = '%'": Return
        bs.Filter = "SHI = '" & drv.Item("SHI").ToString & "'"
    End Sub

    thanks for your reply. OK no problem
    Last edited by roy88; Dec 30th, 2021 at 08:22 AM.

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by .paul. View Post
    Code:
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If bs Is Nothing Then Return
        Dim drv As DataRowView = DirectCast(ComboBox1.SelectedItem, DataRowView)
        If drv.Item("SHI").ToString = "" Then bs.Filter = "SHI = '%'": Return
        bs.Filter = "SHI = '" & drv.Item("SHI").ToString & "'"
    End Sub
    If I use this code the expicturebox appears only on the first line in the datagridview , I want the loading form to still appear in full datagridview

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by .paul. View Post
    I'm not sure why the ExPictureBox loading is slowing your application, except you have 6 of these for which the filename must be found on each row change and also 6 images you're loading...

    I want the expicturebox to appear if I click a cell in the itc column so the process doesn't take long

    or what makes it slow because in the database there is only filename so you have to search for it from the folder and its subfolders.
    Last edited by roy88; Dec 30th, 2021 at 09:30 AM.

  20. #20
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,480

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by roy88 View Post
    I want the expicturebox to appear if I click a cell in the itc column so the process doesn't take long

    or what makes it slow because in the database there is only filename so you have to search for it from the folder and its subfolders.
    That’s not the way databinding works. If you want to change your requirements, you have to use an appropriate dgv event to manually display your images…

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by .paul. View Post
    That’s not the way databinding works. If you want to change your requirements, you have to use an appropriate dgv event to manually display your images…
    do you mean that in the database there must be a full path or location of the image?
    so the solution for displaying images is good and fast because the database has fifteen thousand rows and the image filename has four thousand

  22. #22
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,480

    Re: This causes two bindings in the collection to bind to the same property vb.net

    If you click a row, your images will show. That is databinding. Obviously searching for files takes time.
    If you want to change that so that images only show when you click a cell, that cannot be achieved through databinding.

  23. #23

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by roy88 View Post
    If I use this code the expicturebox appears only on the first line in the datagridview , I want the loading form to still appear in full datagridview
    if I use this code there is a problem so I can't use search in the textbox

  24. #24

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by .paul. View Post
    If you click a row, your images will show. That is databinding. Obviously searching for files takes time.
    If you want to change that so that images only show when you click a cell, that cannot be achieved through databinding.
    if I use the method below then it won't make it slow
    "if you want to change that so that images only show when you click a cell, that cannot be achieved through databinding"

  25. #25
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,480

    Re: This causes two bindings in the collection to bind to the same property vb.net

    You’ve got me playing guessing games again. I’d recommend starting a new thread for this question, and good luck with that, I hope someone else can give you a useful answer…

  26. #26

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by .paul. View Post
    You’ve got me playing guessing games again. I’d recommend starting a new thread for this question, and good luck with that, I hope someone else can give you a useful answer…

    ok for the problem of expicture or display images with different methods in datagridview then I will do a new post but I hope you can help me in my latest post

  27. #27

    Thread Starter
    Lively Member
    Join Date
    Aug 2021
    Posts
    91

    Re: This causes two bindings in the collection to bind to the same property vb.net

    Quote Originally Posted by .paul. View Post
    Code:
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If bs Is Nothing Then Return
        Dim drv As DataRowView = DirectCast(ComboBox1.SelectedItem, DataRowView)
        If drv.Item("SHI").ToString = "" Then bs.Filter = "SHI = '%'": Return
        bs.Filter = "SHI = '" & drv.Item("SHI").ToString & "'"
    End Sub
    for now the problem for the combobox filter is not perfect because I can't use the search textbox every time I type a character it immediately appears "No match found" , and also I want the initial loading screen to appear full datagridview and another for the combobox filter column sequentially like A-Z
    Code:
    Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
     Try
                CType(DataGridView1.DataSource, DataTable).DefaultView.RowFilter = String.Format("ITM LIKE '%{0}%' OR ITM LIKE '%{0}%'", TextBox1.Text)
    Catch ex As Exception
                MsgBox("No match found")
            End Try
        End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width