Results 1 to 27 of 27

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

Threaded View

  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.

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