S
Shan1986
Guest
Hallo
I have 3 cascading combo boxes and 3 text boxes, all the values are bound to data table by a binding source. I want to clear/empty the text boxes when i change or select the item in the combo boxes manually my code clears the data table values and clears the textbox but combobox item is not changing. it stays the same why?.
Imports System.IO
Public Class Form1
Public BS As New BindingSource
Public ds2 As New DataSet
Public XML_DS As New DataSet
Public ds As New DataSet
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Call create_DAT()
XML_DS.ReadXml("XML\L1.xml")
BS.DataSource = ds2.Tables("Master")
dgv.DataSource = BS
cb1.DataSource = XML_DS.Tables("L1")
cb1.DisplayMember = "eNAME"
cb1.ValueMember = "eID"
cb1.DataBindings.Add("Text", BS, "Master")
cb2.DataSource = XML_DS.Tables("L2")
cb2.DisplayMember = "eTYPE"
cb2.ValueMember = "tID"
cb2.DataBindings.Add("Text", BS, "Child")
cb3.DataSource = XML_DS.Tables("L3")
cb3.DisplayMember = "eMAT"
cb3.ValueMember = "mID"
cb3.DataBindings.Add("Text", BS, "Grand_Child")
tb1.DataBindings.Add("Text", BS, "Text1", True, DataSourceUpdateMode.OnPropertyChanged, String.Empty)
tb2.DataBindings.Add("Text", BS, "Text2", True, DataSourceUpdateMode.OnPropertyChanged, String.Empty)
tb3.DataBindings.Add("Text", BS, "Text3", True, DataSourceUpdateMode.OnPropertyChanged, String.Empty)
AddHandler BS.BindingComplete, AddressOf BindingComplete
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Call add()
End Sub
Private Sub cb1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cb1.SelectedValueChanged
cb2.DataSource = New DataView(XML_DS.Tables("L2"), $"eID= '{cb1.SelectedValue}'", "", DataViewRowState.CurrentRows)
End Sub
Private Sub cb2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cb2.SelectedValueChanged
cb3.DataSource = New DataView(XML_DS.Tables("L3"), $"tID= '{cb2.SelectedValue}'", "", DataViewRowState.CurrentRows)
End Sub
Private Sub cb1_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles cb1.SelectionChangeCommitted
Dim nRow = DirectCast(BS.Current, DataRowView)
If Not nRow Is Nothing Then
nRow("Text1") = String.Empty
nRow("Text2") = String.Empty
nRow("Text3") = String.Empty
End If
tb1.Text = String.Empty
tb2.Text = String.Empty
tb3.Text = String.Empty
End Sub
Public Sub create_DAT()
With ds2
With .Tables.Add("Master")
With .Columns
.Add("Master", GetType(String))
.Add("Child", GetType(String))
.Add("Grand_Child", GetType(String))
.Add("Text1", GetType(String))
.Add("Text2", GetType(String))
.Add("Text3", GetType(String))
End With
End With
End With
End Sub
Public Sub BindingComplete(ByVal sender As Object, ByVal e As BindingCompleteEventArgs)
If e.BindingCompleteContext = BindingCompleteContext.DataSourceUpdate AndAlso e.Exception Is Nothing Then e.Binding.BindingManagerBase.EndCurrentEdit()
End Sub
Public Sub add()
Dim cb11 As String = cb1.Text
Dim cb12 As String = cb2.Text
Dim cb13 As String = cb3.Text
Dim t1 As String = "xxxx"
Dim nRow = DirectCast(BS.AddNew(), DataRowView)
nRow("Master") = cb11
nRow("Child") = cb12
nRow("Grand_Child") = cb13
nRow("Text1") = t1
nRow("Text2") = t1
nRow("Text3") = t1
BS.EndEdit()
End Sub
End Class
XML
<?xml version="1.0" encoding="UTF-8"?>
-<dataroot generated="2020-08-15T14:54:41" xmlnsd="urn:schemas-microsoft-comfficedata">
-<L1>
<eID>VG</eID>
<eNAME>Vegis</eNAME>
-<L2>
<tID>VG.01</tID>
<eID>VG</eID>
<eTYPE>Carrot</eTYPE>
-<L3>
<mID>VG.01.1K</mID>
<tID>VG.01</tID>
<eMAT>Caarot 1kg</eMAT>
</L3>
-<L3>
<mID>VG.01.2K</mID>
<tID>VG.01</tID>
<eMAT>Caarot 2kg</eMAT>
</L3>
</L2>
-<L2>
<tID>VG.02</tID>
<eID>VG</eID>
<eTYPE>Onions</eTYPE>
-<L3>
<mID>VG.02.1k</mID>
<tID>VG.02</tID>
<eMAT>Onions 1kg</eMAT>
</L3>
-<L3>
<mID>VG.02.2K</mID>
<tID>VG.02</tID>
<eMAT>Onions 2kg</eMAT>
</L3>
</L2>
-<L2>
<tID>VG.03</tID>
<eID>VG</eID>
<eTYPE>Potato</eTYPE>
-<L3>
<mID>VG.03.1K</mID>
<tID>VG.03</tID>
<eMAT>Potato 1Kg</eMAT>
</L3>
-<L3>
<mID>VG.03.2K</mID>
<tID>VG.03</tID>
<eMAT>Potato 2Kg</eMAT>
</L3>
</L2>
</L1>
-<L1>
<eID>FR</eID>
<eNAME>Fruits</eNAME>
-<L2>
<tID>FR.01</tID>
<eID>FR</eID>
<eTYPE>Apple</eTYPE>
-<L3>
<mID>FR.01.F1</mID>
<tID>FR.01</tID>
<eMAT>Apple 1K</eMAT>
</L3>
-<L3>
<mID>FR.01.F2</mID>
<tID>FR.01</tID>
<eMAT>Apple 2K</eMAT>
</L3>
</L2>
-<L2>
<tID>FR.02</tID>
<eID>FR</eID>
<eTYPE>Banana</eTYPE>
-<L3>
<mID>FR.02.B1</mID>
<tID>FR.02</tID>
<eMAT>Banana 1k</eMAT>
</L3>
</L2>
-<L2>
<tID>FR.03</tID>
<eID>FR</eID>
<eTYPE>Figs</eTYPE>
-<L3>
<mID>FR.03.FI</mID>
<tID>FR.03</tID>
<eMAT>1kg</eMAT>
</L3>
</L2>
</L1>
-<L1>
<eID>MT</eID>
<eNAME>Meats</eNAME>
-<L2>
<tID>MT.01</tID>
<eID>MT</eID>
<eTYPE>Fish</eTYPE>
-<L3>
<mID>MT.01.FI</mID>
<tID>MT.01</tID>
<eMAT>Fish 1k</eMAT>
</L3>
-<L3>
<mID>MT.01.FI2</mID>
<tID>MT.01</tID>
<eMAT>Fish 2k</eMAT>
</L3>
</L2>
-<L2>
<tID>MT.02</tID>
<eID>MT</eID>
<eTYPE>Chicken</eTYPE>
-<L3>
<mID>MT.02.C1</mID>
<tID>MT.02</tID>
<eMAT>1k</eMAT>
</L3>
-<L3>
<mID>MT.02.C2</mID>
<tID>MT.02</tID>
<eMAT>2K</eMAT>
</L3>
</L2>
-<L2>
<tID>MT.03</tID>
<eID>MT</eID>
<eTYPE>Mutton</eTYPE>
-<L3>
<mID>MT.03.M1</mID>
<tID>MT.03</tID>
<eMAT>1K</eMAT>
</L3>
-<L3>
<mID>MT.03.M2</mID>
<tID>MT.03</tID>
<eMAT>2K</eMAT>
</L3>
</L2>
</L1>
-<L1>
<eID>DR</eID>
<eNAME>Dairy</eNAME>
-<L2>
<tID>DR.01</tID>
<eID>DR</eID>
<eTYPE>Milk</eTYPE>
-<L3>
<mID>DR.01.MI1</mID>
<tID>DR.01</tID>
<eMAT>1L</eMAT>
</L3>
-<L3>
<mID>DR.01.MI2</mID>
<tID>DR.01</tID>
<eMAT>2L</eMAT>
</L3>
</L2>
-<L2>
<tID>DR.02</tID>
<eID>DR</eID>
<eTYPE>Curd</eTYPE>
-<L3>
<mID>DR.02.C1</mID>
<tID>DR.02</tID>
<eMAT>5 Pack</eMAT>
</L3>
-<L3>
<mID>DR.02.C2</mID>
<tID>DR.02</tID>
<eMAT>12 Pack</eMAT>
</L3>
</L2>
-<L2>
<tID>DR.03</tID>
<eID>DR</eID>
<eTYPE>Cheese</eTYPE>
-<L3>
<mID>DR.03.CH1</mID>
<tID>DR.03</tID>
<eMAT>500g</eMAT>
</L3>
-<L3>
<mID>DR.03.CH2</mID>
<tID>DR.03</tID>
<eMAT>1kg</eMAT>
</L3>
</L2>
</L1>
-<L1>
<eID>CH</eID>
<eNAME>Chokos</eNAME>
-<L2>
<tID>CH.01</tID>
<eID>CH</eID>
<eTYPE>Chocolate1</eTYPE>
-<L3>
<mID>CH.01.CC1</mID>
<tID>CH.01</tID>
<eMAT>5pck</eMAT>
</L3>
</L2>
-<L2>
<tID>CH.02</tID>
<eID>CH</eID>
<eTYPE>Chocolate2</eTYPE>
-<L3>
<mID>CH.02.CC2</mID>
<tID>CH.02</tID>
<eMAT>10pck</eMAT>
</L3>
</L2>
-<L2>
<tID>CH.03</tID>
<eID>CH</eID>
<eTYPE>Chocolate3</eTYPE>
-<L3>
<mID>CH.02.CC3</mID>
<tID>CH.03</tID>
<eMAT>20pck</eMAT>
</L3>
</L2>
</L1>
-<L1>
<eID>CK</eID>
<eNAME>Cakes</eNAME>
-<L2>
<tID>CK.01</tID>
<eID>CK</eID>
<eTYPE>Cake1</eTYPE>
-<L3>
<mID>CK.01.01</mID>
<tID>CK.01</tID>
<eMAT>200g</eMAT>
</L3>
</L2>
-<L2>
<tID>CK.02</tID>
<eID>CK</eID>
<eTYPE>Cake2</eTYPE>
-<L3>
<mID>CK.02.01</mID>
<tID>CK.02</tID>
<eMAT>300g</eMAT>
</L3>
</L2>
-<L2>
<tID>CK.03</tID>
<eID>CK</eID>
<eTYPE>Cake3</eTYPE>
-<L3>
<mID>CK.03.01</mID>
<tID>CK.03</tID>
<eMAT>500g</eMAT>
</L3>
</L2>
</L1>
</dataroot>
Continue reading...
I have 3 cascading combo boxes and 3 text boxes, all the values are bound to data table by a binding source. I want to clear/empty the text boxes when i change or select the item in the combo boxes manually my code clears the data table values and clears the textbox but combobox item is not changing. it stays the same why?.
Imports System.IO
Public Class Form1
Public BS As New BindingSource
Public ds2 As New DataSet
Public XML_DS As New DataSet
Public ds As New DataSet
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Call create_DAT()
XML_DS.ReadXml("XML\L1.xml")
BS.DataSource = ds2.Tables("Master")
dgv.DataSource = BS
cb1.DataSource = XML_DS.Tables("L1")
cb1.DisplayMember = "eNAME"
cb1.ValueMember = "eID"
cb1.DataBindings.Add("Text", BS, "Master")
cb2.DataSource = XML_DS.Tables("L2")
cb2.DisplayMember = "eTYPE"
cb2.ValueMember = "tID"
cb2.DataBindings.Add("Text", BS, "Child")
cb3.DataSource = XML_DS.Tables("L3")
cb3.DisplayMember = "eMAT"
cb3.ValueMember = "mID"
cb3.DataBindings.Add("Text", BS, "Grand_Child")
tb1.DataBindings.Add("Text", BS, "Text1", True, DataSourceUpdateMode.OnPropertyChanged, String.Empty)
tb2.DataBindings.Add("Text", BS, "Text2", True, DataSourceUpdateMode.OnPropertyChanged, String.Empty)
tb3.DataBindings.Add("Text", BS, "Text3", True, DataSourceUpdateMode.OnPropertyChanged, String.Empty)
AddHandler BS.BindingComplete, AddressOf BindingComplete
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Call add()
End Sub
Private Sub cb1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cb1.SelectedValueChanged
cb2.DataSource = New DataView(XML_DS.Tables("L2"), $"eID= '{cb1.SelectedValue}'", "", DataViewRowState.CurrentRows)
End Sub
Private Sub cb2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cb2.SelectedValueChanged
cb3.DataSource = New DataView(XML_DS.Tables("L3"), $"tID= '{cb2.SelectedValue}'", "", DataViewRowState.CurrentRows)
End Sub
Private Sub cb1_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles cb1.SelectionChangeCommitted
Dim nRow = DirectCast(BS.Current, DataRowView)
If Not nRow Is Nothing Then
nRow("Text1") = String.Empty
nRow("Text2") = String.Empty
nRow("Text3") = String.Empty
End If
tb1.Text = String.Empty
tb2.Text = String.Empty
tb3.Text = String.Empty
End Sub
Public Sub create_DAT()
With ds2
With .Tables.Add("Master")
With .Columns
.Add("Master", GetType(String))
.Add("Child", GetType(String))
.Add("Grand_Child", GetType(String))
.Add("Text1", GetType(String))
.Add("Text2", GetType(String))
.Add("Text3", GetType(String))
End With
End With
End With
End Sub
Public Sub BindingComplete(ByVal sender As Object, ByVal e As BindingCompleteEventArgs)
If e.BindingCompleteContext = BindingCompleteContext.DataSourceUpdate AndAlso e.Exception Is Nothing Then e.Binding.BindingManagerBase.EndCurrentEdit()
End Sub
Public Sub add()
Dim cb11 As String = cb1.Text
Dim cb12 As String = cb2.Text
Dim cb13 As String = cb3.Text
Dim t1 As String = "xxxx"
Dim nRow = DirectCast(BS.AddNew(), DataRowView)
nRow("Master") = cb11
nRow("Child") = cb12
nRow("Grand_Child") = cb13
nRow("Text1") = t1
nRow("Text2") = t1
nRow("Text3") = t1
BS.EndEdit()
End Sub
End Class
XML
<?xml version="1.0" encoding="UTF-8"?>
-<dataroot generated="2020-08-15T14:54:41" xmlnsd="urn:schemas-microsoft-comfficedata">
-<L1>
<eID>VG</eID>
<eNAME>Vegis</eNAME>
-<L2>
<tID>VG.01</tID>
<eID>VG</eID>
<eTYPE>Carrot</eTYPE>
-<L3>
<mID>VG.01.1K</mID>
<tID>VG.01</tID>
<eMAT>Caarot 1kg</eMAT>
</L3>
-<L3>
<mID>VG.01.2K</mID>
<tID>VG.01</tID>
<eMAT>Caarot 2kg</eMAT>
</L3>
</L2>
-<L2>
<tID>VG.02</tID>
<eID>VG</eID>
<eTYPE>Onions</eTYPE>
-<L3>
<mID>VG.02.1k</mID>
<tID>VG.02</tID>
<eMAT>Onions 1kg</eMAT>
</L3>
-<L3>
<mID>VG.02.2K</mID>
<tID>VG.02</tID>
<eMAT>Onions 2kg</eMAT>
</L3>
</L2>
-<L2>
<tID>VG.03</tID>
<eID>VG</eID>
<eTYPE>Potato</eTYPE>
-<L3>
<mID>VG.03.1K</mID>
<tID>VG.03</tID>
<eMAT>Potato 1Kg</eMAT>
</L3>
-<L3>
<mID>VG.03.2K</mID>
<tID>VG.03</tID>
<eMAT>Potato 2Kg</eMAT>
</L3>
</L2>
</L1>
-<L1>
<eID>FR</eID>
<eNAME>Fruits</eNAME>
-<L2>
<tID>FR.01</tID>
<eID>FR</eID>
<eTYPE>Apple</eTYPE>
-<L3>
<mID>FR.01.F1</mID>
<tID>FR.01</tID>
<eMAT>Apple 1K</eMAT>
</L3>
-<L3>
<mID>FR.01.F2</mID>
<tID>FR.01</tID>
<eMAT>Apple 2K</eMAT>
</L3>
</L2>
-<L2>
<tID>FR.02</tID>
<eID>FR</eID>
<eTYPE>Banana</eTYPE>
-<L3>
<mID>FR.02.B1</mID>
<tID>FR.02</tID>
<eMAT>Banana 1k</eMAT>
</L3>
</L2>
-<L2>
<tID>FR.03</tID>
<eID>FR</eID>
<eTYPE>Figs</eTYPE>
-<L3>
<mID>FR.03.FI</mID>
<tID>FR.03</tID>
<eMAT>1kg</eMAT>
</L3>
</L2>
</L1>
-<L1>
<eID>MT</eID>
<eNAME>Meats</eNAME>
-<L2>
<tID>MT.01</tID>
<eID>MT</eID>
<eTYPE>Fish</eTYPE>
-<L3>
<mID>MT.01.FI</mID>
<tID>MT.01</tID>
<eMAT>Fish 1k</eMAT>
</L3>
-<L3>
<mID>MT.01.FI2</mID>
<tID>MT.01</tID>
<eMAT>Fish 2k</eMAT>
</L3>
</L2>
-<L2>
<tID>MT.02</tID>
<eID>MT</eID>
<eTYPE>Chicken</eTYPE>
-<L3>
<mID>MT.02.C1</mID>
<tID>MT.02</tID>
<eMAT>1k</eMAT>
</L3>
-<L3>
<mID>MT.02.C2</mID>
<tID>MT.02</tID>
<eMAT>2K</eMAT>
</L3>
</L2>
-<L2>
<tID>MT.03</tID>
<eID>MT</eID>
<eTYPE>Mutton</eTYPE>
-<L3>
<mID>MT.03.M1</mID>
<tID>MT.03</tID>
<eMAT>1K</eMAT>
</L3>
-<L3>
<mID>MT.03.M2</mID>
<tID>MT.03</tID>
<eMAT>2K</eMAT>
</L3>
</L2>
</L1>
-<L1>
<eID>DR</eID>
<eNAME>Dairy</eNAME>
-<L2>
<tID>DR.01</tID>
<eID>DR</eID>
<eTYPE>Milk</eTYPE>
-<L3>
<mID>DR.01.MI1</mID>
<tID>DR.01</tID>
<eMAT>1L</eMAT>
</L3>
-<L3>
<mID>DR.01.MI2</mID>
<tID>DR.01</tID>
<eMAT>2L</eMAT>
</L3>
</L2>
-<L2>
<tID>DR.02</tID>
<eID>DR</eID>
<eTYPE>Curd</eTYPE>
-<L3>
<mID>DR.02.C1</mID>
<tID>DR.02</tID>
<eMAT>5 Pack</eMAT>
</L3>
-<L3>
<mID>DR.02.C2</mID>
<tID>DR.02</tID>
<eMAT>12 Pack</eMAT>
</L3>
</L2>
-<L2>
<tID>DR.03</tID>
<eID>DR</eID>
<eTYPE>Cheese</eTYPE>
-<L3>
<mID>DR.03.CH1</mID>
<tID>DR.03</tID>
<eMAT>500g</eMAT>
</L3>
-<L3>
<mID>DR.03.CH2</mID>
<tID>DR.03</tID>
<eMAT>1kg</eMAT>
</L3>
</L2>
</L1>
-<L1>
<eID>CH</eID>
<eNAME>Chokos</eNAME>
-<L2>
<tID>CH.01</tID>
<eID>CH</eID>
<eTYPE>Chocolate1</eTYPE>
-<L3>
<mID>CH.01.CC1</mID>
<tID>CH.01</tID>
<eMAT>5pck</eMAT>
</L3>
</L2>
-<L2>
<tID>CH.02</tID>
<eID>CH</eID>
<eTYPE>Chocolate2</eTYPE>
-<L3>
<mID>CH.02.CC2</mID>
<tID>CH.02</tID>
<eMAT>10pck</eMAT>
</L3>
</L2>
-<L2>
<tID>CH.03</tID>
<eID>CH</eID>
<eTYPE>Chocolate3</eTYPE>
-<L3>
<mID>CH.02.CC3</mID>
<tID>CH.03</tID>
<eMAT>20pck</eMAT>
</L3>
</L2>
</L1>
-<L1>
<eID>CK</eID>
<eNAME>Cakes</eNAME>
-<L2>
<tID>CK.01</tID>
<eID>CK</eID>
<eTYPE>Cake1</eTYPE>
-<L3>
<mID>CK.01.01</mID>
<tID>CK.01</tID>
<eMAT>200g</eMAT>
</L3>
</L2>
-<L2>
<tID>CK.02</tID>
<eID>CK</eID>
<eTYPE>Cake2</eTYPE>
-<L3>
<mID>CK.02.01</mID>
<tID>CK.02</tID>
<eMAT>300g</eMAT>
</L3>
</L2>
-<L2>
<tID>CK.03</tID>
<eID>CK</eID>
<eTYPE>Cake3</eTYPE>
-<L3>
<mID>CK.03.01</mID>
<tID>CK.03</tID>
<eMAT>500g</eMAT>
</L3>
</L2>
</L1>
</dataroot>
Continue reading...