referencing a custom class instance  
Author Message
AlexBB





PostPosted: Visual C# General, referencing a custom class instance Top

Mine is a .NET C# app on VS2005.

I have a "main" form class Form1 and a number of classes that are used on demand. One of them is CandlePlot. CandlePlot is instantiated in a function Funct1 which is called by a Click method. Funct1 creates the plot and places it on a newly generated TabPage. So far so good.

Most of the code plot related I downloaded as a demo from NPlot.com website. It is great and honest software. I just need to improve it introducing some dynamic elements which appear to be absent in the original. The CandlePlot Class has DataSource property. Inside Funct1 where the Class CandlePlot is instantiated I initialize this property by assigning a DataTable to it. The DataTable is supplied as a parameter in a list or arguments to Funct1. I also want to mention that I intend to generate a few instances of this class to have a few plots positioned on a few TabPages. Here is my problem.

The way it is set up now the plot is static. If the original dataset is updated I cannot find a way to update the DataSource with a new DataTable which will have perhaps one extra row added to the bottom. I am looking for a way to reference the instance of the CandlePlot "cp." So far I haven't been able to find a way to do it.

I tried numerous things. In particular I tried to set up an ArrayList arrListForm1 in Form1 class and add every instance of cp to that list while in Funct1. The collection went OK but the idea did not work because I could not see the cp object in the Intellisense menu. Then I tried to type it with <CandlePlot> type but got an error which is reproduced below. Non-generic types are not welcome.

public ArrayList <CandlePlot> arrListForm1 = new ArrayList ( );
Error 1 The non-generic type 'System.Collections.ArrayList' cannot be used with type arguments D:\VCsharp_Projects\tapTCPports_1\Form1.cs 92 16 tapTCPports_1

I would greatly appreciate if someone woud suggest a way to handle this problem. I need to refresh my plots through updatinge the datasource.

Many thanks.




Visual C#9  
 
 
RizwanSharp





PostPosted: Visual C# General, referencing a custom class instance Top

There is not Generic Collection type with name ArrayList<T> but there is an alternate (generic implementation) which you can use.

Try this:

List <CandlePlot> arrListForm1 = new List <CandlePlot>( );

Best Regards,

Rizwan



 
 
AlexBB





PostPosted: Visual C# General, referencing a custom class instance Top

There is not Generic Collection type with name ArrayList<T> but there is an alternate (generic implementation) which you can use.

Try this:

List <CandlePlot> arrListForm1 = new List <CandlePlot>( );

Best Regards,

Rizwan

Thank you Rizwan but I got an error:

Error 1 The non-generic type 'System.Web.UI.MobileControls.List' cannot be used with type arguments D:\VCsharp_Projects\tapTCPports_1\Form1.cs 93 9 tapTCPports_1

As you can see it is essentially the same error.



 
 
James Curran





PostPosted: Visual C# General, referencing a custom class instance Top

You are using 'System.Web.UI.MobileControls.List', when you actually want to use System.Collections.Generic.List'. Check your using directives, and use the fully-qualified names if necesary.



 
 
AlexBB





PostPosted: Visual C# General, referencing a custom class instance Top

You are using 'System.Web.UI.MobileControls.List', when you actually want to use System.Collections.Generic.List'. Check your using directives, and use the fully-qualified names if necesary.

Thank you, James. You've come to the rescue of unwary seafarer at the right time always.

I was thrown into the MobilControls.List direction after I got an error and chose the wrong alternative not realizing the distinction.



 
 
RizwanSharp





PostPosted: Visual C# General, referencing a custom class instance Top

There is not Generic Collection type with name ArrayList<T> but there is an alternate (generic implementation) which you can use.

Try this:

List <CandlePlot> arrListForm1 = new List <CandlePlot>( );

Best Regards,

Rizwan

Thank you Rizwan but I got an error:

Error 1 The non-generic type 'System.Web.UI.MobileControls.List' cannot be used with type arguments D:\VCsharp_Projects\tapTCPports_1\Form1.cs 93 9 tapTCPports_1

As you can see it is essentially the same error.

I Was refering to System.Collections.Generics.List <CandlePlot> arrListForm1 = new System.Collections.Generics.List <CandlePlot>( );

I hope this will Help.

Best Regards,

Rizwan



 
 
AlexBB





PostPosted: Visual C# General, referencing a custom class instance Top

There is not Generic Collection type with name ArrayList<T> but there is an alternate (generic implementation) which you can use.

Try this:

List <CandlePlot> arrListForm1 = new List <CandlePlot>( );

Best Regards,

Rizwan

Thank you Rizwan but I got an error:

Error 1 The non-generic type 'System.Web.UI.MobileControls.List' cannot be used with type arguments D:\VCsharp_Projects\tapTCPports_1\Form1.cs 93 9 tapTCPports_1

As you can see it is essentially the same error.

I Was refering to System.Collections.Generics.List <CandlePlot> arrListForm1 = new System.Collections.Generics.List <CandlePlot>( );

I hope this will Help.

Best Regards,

Rizwan

Thank you Rizwan. This issue has been resolved.

However, unexpectedly, I ran into another referencing problem, closely related to this one. I hate to start a new thread since it will require long background explanations.

As I said I have a DataTable filled in my class Form1 and I pass it as a parameter to the function Funct1. This function generates the plot and then generates a TabPage setting the plot on it. It also generates a button. I use this button to test how I can update my plot. The same Funct1 creates a Click method (function) for this button. When I started testing the whole setup I found that although all my objects from Class Form1 including the DataTable that is used as an original feed for the plot DataSource are visible to Intellisense and referencing the DataTable does not cause any compiler error all parameters of this table like Rows.count, etc are 0s.

As a matter of fact this table is a member of a DataSet. I have to look for it in a for loop and when I start doing it I find that that DataSet.Tables.Count is 0 although when I check the same in the Form1 it is 5, and I expect my table to be the last one (index = 4).

I had this Click method set up in the Class where Funct1 resides (the same namespace though). I then moved it into Class Form1 with the same negative result. It is another stumbling block and I cannot figure out why it is this way.

If my explanation is a bit confusing, I will try to clarify it tomorrow with a diagram. Now I am too tired and want to call it quits for today.

Thank you.



 
 
boban.s





PostPosted: Visual C# General, referencing a custom class instance Top

Problem is not in your code. Probably that chart control reads the table when you set the property and draws the chart with that data. Every change after that in table is not visible on the chart. But probably that control must have a posibility to add the price bars manually. All chart controls have such thing like, add bar by bar. Also it must have a method for editing existing bar. So when you fill the chart with initial intraday or historical data, to continue with adding bar by bar with realtime data.

 
 
AlexBB





PostPosted: Visual C# General, referencing a custom class instance Top

Problem is not in your code. Probably that chart control reads the table when you set the property and draws the chart with that data. Every change after that in table is not visible on the chart. But probably that control must have a posibility to add the price bars manually. All chart controls have such thing like, add bar by bar. Also it must have a method for editing existing bar. So when you fill the chart with initial intraday or historical data, to continue with adding bar by bar with realtime data.

It is a great suggestion. I will look into it.

The TabPage control with a chart on it is created after at least 4 tables are already in the DataSet. The fifth table is created for that particular TabPage before that call to the routine that creates the TabPage (Funct1) is made. It is done in yet another Button.Click method. After the Table for that page (for the graph chart sitting on it) is created it is added to the dataSet making the count = 5.

When the TabPage appears it has a chart and a button on it. The button has Click event handler generated as part of the whole process of new page creation. Naturally the method it refers to is written well in advance and is sitting either in Form1 class or in that class where the page generating function (Funct1) resides--I tried both approaches with the same negative result.

When I click the button on the page that has been just generated I can see that the event handler is being used. A Console.WriteLine gives me that assurance but in that event handler (function sitting in Form1 class) the Dataset.Tables.Count = 0. It kills all my further attempts to replace the DataSource in the graph. The DataSource comes from the fifth DataTable that was recently added and a new row was supposed to be added to it.

I will look into your suggestion, it is encouraging. It may be prohibitively expensive in terms of the labor cost and time for me to handle it and I have tried to avoid it as much as possible for a time being. The chart method does have arrays of input data from which intraday bar presentation is formed. Before it is done, however, the whole array undergoes normalizations and adjustment to physical dimensions of the rectangle. I have written graphs before myself and know what is involved.

In the meantime, if you have any idea why I get an empty DataSet in that event handler I would appreciate if you share it with me.

Actually this is a testing stage. In reality, after debug is over, repainting of the graph will be triggered by a DataTable.Rows.NewRow event. There is a good chance I won't have this problem in there but it is somewhat down the road. I just wanted to see how this will work from a Click method. Also the whole hangup is kind of puzzling and I want to find out if it is something I do not understand about the system.

Many thanks. I always appreciate your input.



 
 
AlexBB





PostPosted: Visual C# General, referencing a custom class instance Top

OK, I cracked the problem after all. The healthiest solution appears to be placing the declaration for the System.Collections.Generic.List into a file where my global variables dwell and declaring it as a public static object. Now I can store pointers to parts of the graph object in this List and reference it from any place in the project.

Also in my previous post I made a mistake in the event name. It is Table.TableNewRow event.

Thanks.



 
 
boban.s





PostPosted: Visual C# General, referencing a custom class instance Top

You must give as some source to be able to think about. I don't have a whole picture about the last problem. But i believe it is some .NET problem, and and easy one.