AdvancedHMI Software
General Category => Open Discussion => Topic started by: bachphi on March 27, 2017, 02:24:45 PM
-
I created a local DB file [DB_Product.mdf] and a DataSet [DB_ProductDataSet.xsd]
Inside the db, I created a table [TB_PartSpec] that contains: Id, PartName, PartNumber, PressureLoLim, ....
On the MainForm, an Add/Change button will ShowDialog of Page2, where you can add/change Part specs.
Also on the mainform is a combobox to select PartName. The combobox is bound to the table as shown below:
(http://s16.postimg.org/5gfq0oool/Dataset_Combo_Box.jpg)
In order to display part details associated with the PartName selected from the combobox, I use its IndexChanged event:
If ComboBox1.SelectedValue IsNot Nothing Then
Label2.Text = DB_ProductDataSet.TB_PartSpec.FindById(ComboBox1.SelectedValue).PartNumber
Label3.Text = DB_ProductDataSet.TB_PartSpec.FindById(ComboBox1.SelectedValue).PressureLoLim
Label4.Text = DB_ProductDataSet.TB_PartSpec.FindById(ComboBox1.SelectedValue).PressureHiLim
End If
This works for me, and the values will be written to PLC later, but I wonder if you would have a better way to handle this.
TIA.
-
You can simply drag the data source onto the form and everything is done automatically.
-
If you read it carefully, that simply action was already done on Page2.
-
Here's another way:
Dim foundRow As DataRow = DB_ProductDataSet.Tables("TB_PartSpec").Rows.Find(ComboBox1.SelectedValue)
Label2.Text = foundRow(2)
Label3.Text = foundRow(3)
-
You can also use DataBinding on your labels which does not require any code:
- Select the label
- In the Properties Window, expand down DataBinding
- Go into the Text
- Select your same BindingSource you are using for the ComboxBox, except with a different column
-
That's really cool!
Now if I use BasicLabel with PLCAddressValue, can the values from TableBindingSource 'write' to PLCAddress without coding?
-
Now if I use BasicLabel with PLCAddressValue, can the values from TableBindingSource 'write' to PLCAddress without coding?
This should work with most of the visual controls. For binding to update properly a control has to implement IBindableComponent. I do not believe the non-visual controls, such as the DataSubscriber, implement the interface so for those it will not work.
The drivers implement the interface which will also allow you to bind property values to project settings.