This forum is meant for questions and discussions about the X# language and tools
lumberjack
Posts: 726 Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa
Post
by lumberjack » Tue Dec 27, 2022 10:25 am
Hi all,
I have the following issue, the following code compiles but generate an error that the cust2sales datamember does not exist. Can anyone see where I am making a mistake?
Code: Select all
PROTECTED METHOD Initialize() AS VOID
LOCAL oDT1, oDT2 AS DataTable
SELF:oButton3:Click += Button3Click
SELF:oIni := jhnIniFile{"BosPubSePush.exe.ini"}
SELF:oDS := System.Data.DataSet{"sales"}
oDT1 := DataTable{"customer"}
oDT1:Columns:Add("customer", typeof(System.String))
FOREACH cItem AS STRING IN oIni:GetItemNames("customer")
VAR oNewR := oDT1:NewRow()
oNewR["customer"] := cItem
oDT1:Rows:Add(oNewR)
NEXT
oDS:Tables:Add(oDT1)
oDT2 := DataTable{"transaction"}
oDT2:Columns:Add("txn_dt", typeof(System.String))
oDT2:Columns:Add("dt_account", typeof(System.String))
oDT2:Columns:Add("ct_account", typeof(System.String))
oDT2:Columns:Add("quantity", typeof(System.Int32))
oDT2:Columns:Add("amount", typeof(System.Int32))
FOREACH cItem AS STRING IN oIni:GetItemNames("transaction")
VAR cSub := oIni:GetString("transaction", cItem)
VAR cols := cSub.Split(";":ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
VAR oNR := oDT2:NewRow()
oNR["txn_dt"] := cItem
FOREACH kvp AS STRING IN cols
VAR col := kvp.Split(":":ToCharArray())
IF col[0]:Contains("account")
oNR[col[0]] := col[1]
ELSE
oNR[col[0]] := Convert.ToInt32(col[1])
ENDIF
NEXT
oDT2:Rows:Add(oNR)
NEXT
oDS:Tables:Add(oDT2)
VAR oDR := System.Data.DataRelation{"cust2sales", ;
oDS:Tables["customer"]:Columns["customer"],;
oDS:Tables["transaction"]:Columns["dt_account"]}
oDS:Relations:Add(oDR)
VAR oBS1 := System.Windows.Forms.BindingSource{}
oBS1:DataSource := oDS
oBS1:DataMember := "customer"
VAR oBS2 := System.Windows.Forms.BindingSource{}
oBS2:DataSource := oDS
// oBS2:DataMember := "cust2sales"
// VAR oBS := System.Windows.Forms.BindingSource{oDS, oDS:Tables["customer"]}
// oDS:Relations:Add(oDR)
SELF:oDataGridView1:DataSource := oBS1
// SELF:oDataGridView1:DataMember := "customer"
SELF:oDataGridView2:DataSource := oBS2
SELF:oDataGridView2:DataMember := "cust2sales" // ****************This line produce the error*******************
SELF:oDataGridView1:Columns["customer"]:Width := 200
RETURN
Thx in advance,
______________________
Johan Nel
Boshof, South Africa
ic2
Posts: 1841 Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland
Post
by ic2 » Tue Dec 27, 2022 10:39 am
Hello Johan,
I am not using this so what I write here probably doesn't make sense, but if I look into the documentation below I'd say they assign values via fields, not directly like you do.
https://learn.microsoft.com/en-us/dotne ... ew=net-7.0
Dick
TerryB1
Posts: 306 Joined: Wed Jan 03, 2018 11:58 am
Post
by TerryB1 » Tue Dec 27, 2022 11:28 am
Hello Johan
I cannot pretend I understand what your code is doing, but is it possible you are getting something that is zero based conflicting with something one based?
Terry
lumberjack
Posts: 726 Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa
Post
by lumberjack » Tue Dec 27, 2022 11:55 am
Hi Terry,
Nope always work with 0 based.
I just can't understand why the Databinding complains it does not find the relationship "cust2sales"...
______________________
Johan Nel
Boshof, South Africa
lumberjack
Posts: 726 Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa
Post
by lumberjack » Tue Dec 27, 2022 12:09 pm
Terry,
Terry post=24882 userid=4511 wrote: Hello Johan
I cannot pretend I understand what your code is doing, but is it possible you are getting something that is zero based conflicting with something one based?
Terry
Here is an example of what I am trying to do:
LINK
______________________
Johan Nel
Boshof, South Africa
TerryB1
Posts: 306 Joined: Wed Jan 03, 2018 11:58 am
Post
by TerryB1 » Tue Dec 27, 2022 2:56 pm
Hi Johan
Thanks for link.
Not had time to fully understand it but get the gist. So this is just a further total guess.
You have the following lines in your code::
VAR oDR := System.Data.DataRelation{"cust2sales", ;
oDS:Tables["customer"]:Columns["customer"],;
oDS:Tables["transaction"]:Columns["dt_account"]}
I wonder if this should be more along the lines of:
VAR oDR := System.Data.DataRelation{"SOMETHING ELSE", ;
oDS:Tables["customer"]:Columns["customer"],;
oDS:Tables["customer"]:Columns["cust2Sales"],;
oDS:Tables["transaction"]:Columns["dt_account"]}
As I said this is a total guess,
Terry
lumberjack
Posts: 726 Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa
Post
by lumberjack » Tue Dec 27, 2022 6:25 pm
Hi Terry,
The cust2sales is not a datacolumn it is merely the name of the relationship.
______________________
Johan Nel
Boshof, South Africa
FFF
Posts: 1552 Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany
Post
by FFF » Tue Dec 27, 2022 7:22 pm
Johan,
like Dick, i know nothing
but i read this in DataGridView:Datamember help:
"However, if this DataSet contains multiple tables, you must set this property to the name of
one of the tables ."
?
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
lumberjack
Posts: 726 Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa
Post
by lumberjack » Wed Dec 28, 2022 12:21 pm
Hi All,
Well in the end solved the issue using some common sense....
All the MS examples shows a oBS1, oBS2 for the datagridviews of the master and detail....
I merely attached oBS1 to both datagridviews and voila all well.
Thanks for your interaction.
Regards,
______________________
Johan Nel
Boshof, South Africa