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
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...
Re: This causes two bindings in the collection to bind to the same property vb.net
Originally Posted by .paul.
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
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
Re: This causes two bindings in the collection to bind to the same property vb.net
Originally Posted by .paul.
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?
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
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
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...
Re: This causes two bindings in the collection to bind to the same property vb.net
Originally Posted by .paul.
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
Re: This causes two bindings in the collection to bind to the same property vb.net
Originally Posted by .paul.
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?.
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
Re: This causes two bindings in the collection to bind to the same property vb.net
Originally Posted by .paul.
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
Re: This causes two bindings in the collection to bind to the same property vb.net
Originally Posted by .paul.
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
Re: This causes two bindings in the collection to bind to the same property vb.net
Originally Posted by .paul.
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.
Re: This causes two bindings in the collection to bind to the same property vb.net
Originally Posted by roy88
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…
Re: This causes two bindings in the collection to bind to the same property vb.net
Originally Posted by .paul.
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
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.
Re: This causes two bindings in the collection to bind to the same property vb.net
Originally Posted by .paul.
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"
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…
Re: This causes two bindings in the collection to bind to the same property vb.net
Originally Posted by .paul.
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
Re: This causes two bindings in the collection to bind to the same property vb.net
Originally Posted by .paul.
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