Build error object reference??

  • Thread starter Thread starter Laura Carr
  • Start date Start date
L

Laura Carr

I have been getting the following error fro an event in an
rpx.cs file. The error is as follows: An object reference
is required for the nonstatic field, method, or
property 'DataDynamics.ActiveReports.ActiveReport.Sections'
Can someone point me in the right direction in terms of
where I am going wrong.

private void Detail_Format(object sender, System.EventArgs
eArgs)
{
if(((CheckBox)Test.Sections["Detail"].Controls
["chcomplaint"]).DataField == "1")
{
((CheckBox)Test.Sections["Detail"].Controls
["chcomplaint"]).Checked = true;
}
else
{
((CheckBox)Test.Sections["Detail"].Controls
["chcomplaint"]).Checked = false;
}

}
 
Laura Carr said:
I have been getting the following error fro an event in an
rpx.cs file. The error is as follows: An object reference
is required for the nonstatic field, method, or
property 'DataDynamics.ActiveReports.ActiveReport.Sections'
Can someone point me in the right direction in terms of
where I am going wrong.

private void Detail_Format(object sender, System.EventArgs
eArgs)
{
if(((CheckBox)Test.Sections["Detail"].Controls
["chcomplaint"]).DataField == "1")
{
((CheckBox)Test.Sections["Detail"].Controls
["chcomplaint"]).Checked = true;
}
else
{
((CheckBox)Test.Sections["Detail"].Controls
["chcomplaint"]).Checked = false;
}

}

It's not entirely clear - what's "Test" in this case?

Btw, your code could be made a lot cleaner by separating things out:

CheckBox cb =(CheckBox)Test.Sections["Detail"].Controls["chcomplaint"];

if (cb.DataField=="1")
{
cb.Checked = true;
}
else
{
cb.Checked = false;
}

The if/else block could then be changed to:

cb.Checked = (cb.DataField=="1");
 
Test is the name of the Report file (Test.rpx). I did
what you said and my code now looks like this below.
However I am now getting this build error: An object
reference is required for the nonstatic field, method, or
property 'DataDynamics.ActiveReports.ActiveReport.Sections'
Have you any Idelas what I've done wrong??

CheckBox cb = (CheckBox)Test.Sections["Detail"].Controls
["chcomplaint"];
if (cb.DataField == "1")
{
cb.Checked = true;
}
else
{
cb.Checked = false;
}
 
Laura Carr said:
Test is the name of the Report file (Test.rpx).

Ah. In that case, the problem is that you're trying to use an instance
property as if it were static. You'll need a reference to an instance
of the Test class.
 
Im sorry im really new to coding and im not 100% sure what
you mean here. How do I create a reference to an instance
of a Test class and where abouts should I do this. Thanks
so much for your help.
 
Laura Carr said:
Im sorry im really new to coding and im not 100% sure what
you mean here. How do I create a reference to an instance
of a Test class and where abouts should I do this. Thanks
so much for your help.

I don't know about reports, to be honest, which is a problem here -
chances are there's already an instance of Test somewhere, but without
knowing more about reports I can't really tell you how to find it.

I would *strongly* suggest that you start from scratch and learn "plain
C#" first, then start learning about reports when you're comfortable
with C# itself. That way you'll find a lot of the concepts a lot less
daunting, and will be able to solve problems like this easily.
 
Hi Laura,

While I have never worked with ActiveReports just with CR I assume they
follow the same way of building them. I tell you this cause the explanatio
below is based on CR no on ActiveReports.

CR create a class named like the report you create, if you create a report
named Report1 you will get two files:
Report1.rpt which contains the data needed by the designer and I assume the
report itself, and other named Report1.cs this is the code used in your
program, there you have a Report1 class that derived from Report which is
the abstract base class.

After all this explanation what I think is happening is that you are not
creating a new instance of the report, just using the name of the report
which is a type ( class )
You have to create an instance first:

Report test = new Report1();

Again, remember that the above is valid for CR but I can bet that it's what
you are seeing

Cheers,
 
Back
Top