M
MB
Hello!
I have a panel in a form where to add controls, where the properties are loaded from a database, and the properties also are visible in a gridview (from developers express). The strange thing is that when I change the row in the gridview that object will be the visible one, and when checking (for each control...) the controls in the panel it's properties are equal to eachother, which they shouldn't (are not in the database). I think I've missed something with the binding, but I can't figure out what. Below you can see some of my code which loads the controls into the tab:
Regards Magnus
Private Sub LoadControlsTmp()
Dim st As String = "Prospects_Controls"
Dim cmd As New SqlClient.SqlCommand("select * from " & st & " where _TabID=" & cmbTabs.SelectedItem.IntID, cn)
da.SelectCommand = cmd
If ds.Tables.Count > 0 Then ds.Tables.Clear()
da.Fill(ds, st)
Panel3.Controls.Clear()
Dim dv As DataView = ds.Tables(st).DefaultView
GrdControl3.DataSource = dv
Dim drCTRL As DataRowView
For Each drCTRL In dv
Dim obj As New TextBox
obj.DataBindings.Add(New Binding("Text", dv, "CtrlText"))
obj.DataBindings.Add(New Binding("Name", dv, "CtrlName"))
Panel3.Controls.Add(obj)
Next
End Sub
I have a panel in a form where to add controls, where the properties are loaded from a database, and the properties also are visible in a gridview (from developers express). The strange thing is that when I change the row in the gridview that object will be the visible one, and when checking (for each control...) the controls in the panel it's properties are equal to eachother, which they shouldn't (are not in the database). I think I've missed something with the binding, but I can't figure out what. Below you can see some of my code which loads the controls into the tab:
Regards Magnus
Private Sub LoadControlsTmp()
Dim st As String = "Prospects_Controls"
Dim cmd As New SqlClient.SqlCommand("select * from " & st & " where _TabID=" & cmbTabs.SelectedItem.IntID, cn)
da.SelectCommand = cmd
If ds.Tables.Count > 0 Then ds.Tables.Clear()
da.Fill(ds, st)
Panel3.Controls.Clear()
Dim dv As DataView = ds.Tables(st).DefaultView
GrdControl3.DataSource = dv
Dim drCTRL As DataRowView
For Each drCTRL In dv
Dim obj As New TextBox
obj.DataBindings.Add(New Binding("Text", dv, "CtrlText"))
obj.DataBindings.Add(New Binding("Name", dv, "CtrlName"))
Panel3.Controls.Add(obj)
Next
End Sub