I have one Datatable and I have two Dataviews, I wanted to use each Dataview to fill a Combobox as next code:
Dim xDv_Parents As DataView = MyVar_Dt_AllAccounts.DefaultView
xDv_Parents.RowFilter = "AccType='Main'"
Call xCLS.MyCodes_CboFill_Dv(Me.CboAccParent, "AccName", "AccID", xDv_Parents)
Dim xDv_Final As DataView = MyVar_Dt_AllAccounts.DefaultView
xDv_Final.RowFilter = "AccType='Final'"
Call xCLS.MyCodes_CboFill_Dv(Me.CboAccFinal, "AccName", "AccID", xDv_Final)
but when I debug the app it gives me the same content in two Comboboxs according the last Dataview the named is (xDv_Final).
I tried to use one Dataview with different row filter but it wasn't a success. what's the problem exactly here please!?
It's because you reused the same view for both comboboxes. All you did was establish new variables pointing to the same object in memory. First you had this:
Then you made another variable, same object:
Dim xDv_Parents As DataView = MyVar_Dt_AllAccounts.DefaultView
Then you set a rowfilter:
xDv_Parents.RowFilter = "AccType='Main'"
Then you told one combo to use it, so now you have a combo pointing to it too:
Call xCLS.MyCodes_CboFill_Dv(Me.CboAccParent, "AccName", "AccID", xDv_Parents)
Then you made another variable, also pointing to it, and overwrote the rowfilter you just set:
Dim xDv_Final As DataView = MyVar_Dt_AllAccounts.DefaultView
xDv_Final.RowFilter = "AccType='Final'"
Finally you attached another combo to the same view:
Call xCLS.MyCodes_CboFill_Dv(Me.CboAccFinal, "AccName", "AccID", xDv_Final)
This is just how variables in .net programming languages work. Unless you use New
you're just attaching new variables to existing object instances
What you should have done was:
Dim xDv_Parents = new DataView(MyVar_Dt_AllAccounts)
xDv_Parents.RowFilter = "AccType='Main'"
xCLS.MyCodes_CboFill_Dv(Me.CboAccParent, "AccName", "AccID", xDv_Parents)
Dim xDv_Final = New DataView(MyVar_Dt_AllAccounts.DefaultView)
xDv_Final.RowFilter = "AccType='Final'"
xCLS.MyCodes_CboFill_Dv(Me.CboAccFinal, "AccName", "AccID", xDv_Final)