I would like some help. I have this code:
string hozzaadnivalo;
public override Java.Lang.Object InstantiateItem(ViewGroup container, int position)
{
View view = LayoutInflater.From(container.Context).Inflate(Resource.Layout.pager_item, container, false);
container.AddView(view);
Button hozzaadas = view.FindViewById<Button>(Resource.Id.hozzaad);
var autoCompleteOptions = new string[] { "Sajt", "Tej", "Kecske", "Barátnő", "piros", "alma" };
ArrayAdapter autoCompleteAdapter = new ArrayAdapter(container.Context, Android.Resource.Layout.SimpleDropDownItem1Line, autoCompleteOptions);
AutoCompleteTextView mautoCompleteTextView = view.FindViewById<AutoCompleteTextView>(Resource.Id.autoCompleteTextView1);
mautoCompleteTextView.Adapter = autoCompleteAdapter;
hozzaadas.Click += hozaadasListViewhez;
hozzaadnivalo = mautoCompleteTextView.Text;
}
private void hozaadasListViewhez(object sender, EventArgs e)
{
adapter.Add(mautoCompleteTextView.Text);
adapter.NotifyDataSetChanged();
}
So i want to add the text of the autocompleteTextView to my listview adapter, but i cant do it there because it does not exist there. So I made a string that I makde equal to the mautoCompleteTextView.Text, but it will be empty, because it will run at the program start, when the user havent done anything. So my problem is that i cant get the mautoCompleteTextView.Text when the user has pressed the button. If anyone could halp that would be great thanks.
You are declaring mautoCompleteTextView inside your method, so it is only available locally within that method.
If you move the declaration outside of the method, then mautoCompleteTextView will be available throughout the entire class.
// declare it here
AutoCompleteTextView mautoCompleteTextView;
// then instantiate it within the method
public override Java.Lang.Object InstantiateItem(ViewGroup container, int position)
{
... // code omitted
mautoCompleteTextView = view.FindViewById<AutoCompleteTextView>(Resource.Id.autoCompleteTextView1);
... // code omitted
}
Related
Bear in mind I'm very new to programming. I've managed to set up images as custom markers on bing maps, the images are chosen and placed on the map according to data coming from a JSON feed. I have a list view page where one can view flood warnings, and clicking on an item in this list will take you to another page with further details of that particular flood. I want it so when someone clicks on a marker on the map it will take them to the info page corresponding to that flood. (It's a bit convoluted but I hope this is clear)
I've had great difficulty to get this to work, the code for navigating from the listview to the info page is simple enough,
private void listBoxBeaches_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
GetSelectedItem();
}
private void GetSelectedItem()
{
RootObject item = listBoxBeaches.SelectedItem as RootObject;
ArDe = item.AreaDescription;
SeTe = item.SeverityTxt;
Rais = item.RaisedF;
MesEng = item.MessageEnglish;
MesCym = item.MessageWelsh;
if (item != null)
{
NavigationService.Navigate(new Uri(string.Format("/AlertInfoPage.xaml?area={0}&sev={1}&rais={2}&meseng={3}&mescym={4}",ArDe,SeTe,Rais,MesEng,MesCym) ,UriKind.Relative));
}
}
But in attempting to get the markers clickable so that it navigates to the same place has been problematic,
public string ArDe;
public string SeTe;
public string Rais;
public string MesEng;
public string MesCym;
public Grid marker;
public NavigationService navServ;
private Map myMap = new Map();
private MapLayer mylayer = new MapLayer();
public Map SetMapPins(List<RootObject>FloodList)
{
myMap.LandmarksEnabled = true;
myMap.PedestrianFeaturesEnabled = true;
myMap.Center = new GeoCoordinate(52.44, -4);
myMap.ZoomLevel = 7.8;
myMap.CartographicMode = MapCartographicMode.Road;
foreach (var flood in FloodList)
{
//this grabs the marker graphic
marker = flood.GetGrid();
MapOverlay myOverlay = new MapOverlay();
myOverlay.GeoCoordinate = new GeoCoordinate(flood.Center.Latitude, flood.Center.Longitude);
string AreaDes = flood.AreaDescription;
string SeverityTxt = flood.SeverityTxt;
string Raised = flood.Raised;
string EngMessage = flood.MessageEnglish;
string CymMessage = flood.MessageWelsh;
marker.MouseLeftButtonUp += (sender, args) => Floodpic_MouseLeftButtonUp(null, null, AreaDes, SeverityTxt, Raised, EngMessage, CymMessage);
myOverlay.Content = marker;
mylayer.Add(myOverlay);
}
myMap.Layers.Add(mylayer);
return myMap;
}
private void Floodpic_MouseLeftButtonUp(object sender, MouseButtonEventArgs e, string AreaDes, string SeverityTxt, string Raised, string EngMessage, string CymMessage)
{
GetSelectedMapItem(AreaDes, SeverityTxt, Raised, EngMessage, CymMessage);
}
public void GetSelectedMapItem(string AreaDes, string SeverityTxt, string Raised, string EngMessage, string CymMessage)
{
ArDe = AreaDes;
SeTe = SeverityTxt;
Rais = Raised;
MesEng = EngMessage;
MesCym = CymMessage;
//initially I used NavigationService.Navigate(new Uri(string.Format("/AlertInfoPage.xaml?area={0}&sev={1}&rais={2}&meseng={3}&mescym={4}",ArDe,SeTe,Rais,MesEng,MesCym) ,UriKind.Relative));
//but this gives me "An object reference is required for the non-static field method or property 'System.Windows.Navigation.NavigationService.Navigate(System.Uri)" error
Navigate(navServ, new Uri(string.Format("/AlertInfoPage.xaml?area={0}&sev={1}&rais={2}&meseng={3}&mescym={4}", ArDe, SeTe, Rais, MesEng, MesCym), UriKind.Relative));
}
public void Navigate(NavigationService s, Uri destination)
{
//This is where the AccessViolationException is thrown
s.Navigate(destination);
}
Just so it's clear, the listview code is navigating from the actual listview page (ListView.xaml.cs), while the marker code is not in the cs file of the page I'm navigating from (in SetMap.cs, not MapView.xaml.cs where the map and markers are) i.e. it navigates externally.
So I'm not sure what to do to get past this, I created the Navigation method due to getting an object reference is required error for
NavigationService.Navigate(new Uri(string.Format("/AlertInfoPage.xaml?area={0}&sev={1}&rais={2}&meseng={3}&mescym={4}",ArDe,SeTe,Rais,MesEng,MesCym) ,UriKind.Relative));
even after trying
this.NavigationService.Navigate(new Uri(string.Format("/AlertInfoPage.xaml?area={0}&sev={1}&rais={2}&meseng={3}&mescym={4}",ArDe,SeTe,Rais,MesEng,MesCym) ,UriKind.Relative));
Now I'm getting the AccessViolationException thrown when Navigate is called. Any ideas?
EDIT
I've gone for a simpler solution for now (using CustomMessageBox, it gets the job done) but I'd still greatly appreciate a solution to this. I understand that this might be an incredibly specific problem and thus might require an equally specific answer. The code is a bit mish mashed but that's due to my lack of training or experience.
Try this path if your page is on root.
NavigationService.Navigate(new Uri(string.Format("~/AlertInfoPage.xaml?area={0}&sev={1}&rais={2}&meseng={3}&mescym={4}",ArDe,SeTe,Rais,MesEng,MesCym) ,UriKind.Relative));
you can not call NavigationService.Navigate in constructor.
OR
if your are navigating from usercontrol.
RootFrame.Navigate(new Uri(string.Format("~/AlertInfoPage.xaml?area={0}&sev={1}&rais={2}&meseng={3}&mescym={4}",ArDe,SeTe,Rais,MesEng,MesCym) ,UriKind.Relative));
I have a UserControl which I am loading into a div which is inside an UpdatePanel. Here is my code for loading it:
controls.IDLControl IdlControl = LoadControl(#"~/controls/IDLControl.ascx") as controls.IDLControl;
IdlControl.ClientIDMode = ClientIDMode.Static;
IdlControl.ID = "IDLControl";
spGroup.Controls.Clear();
spGroup.Controls.Add(IdlControl);
And here is my code for trying to retrieve an instance of it:
controls.IDLControl IdlControl = RecursiveFindControl(this, "IDLControl") as controls.IDLControl;
private Control RecursiveFindControl(Control targetControl, string findControlId) {
if (targetControl.HasControls()) {
foreach (Control childControl in targetControl.Controls) {
if (childControl.ID == findControlId) {
return childControl;
}
RecursiveFindControl(childControl, findControlId);
}
}
return null;
}
But, all I get is null. I need help on figuring this out.
AFAIK, I need to re-add the control to the page on pre-init but it is one of the controls that can be added depending on which option is selected from a drop down list (which also is filled dynamically). I am stuck trying to figure out how to make this work.
You can try something like this to add your control back in the Page_Init based on the option selected in your DropDownList.
protected void Page_Init(Object sender, EventArgs e)
{
if (IsPostBack)
{
if (drpYourDropDown.Items.Count > 0 && drpYourDropDown.SelectedItem.Text == "yourOption")
{
AddIDLControl();
}
}
}
private void AddIDLControl()
{
controls.IDLControl IdlControl = LoadControl(#"~/controls/IDLControl.ascx") as controls.IDLControl;
IdlControl.ClientIDMode = ClientIDMode.Static;
IdlControl.ID = "IDLControl";
spGroup.Controls.Clear();
spGroup.Controls.Add(IdlControl);
}
I have a class that is a list of class objects.
[Serializable]
public class UserRequestOrders
{
private List<RTORequestOrder> m_thisUsersOrders = new List<RTORequestOrder>();
public List<RTORequestOrder> RequestOrders
{
get { return m_thisUsersOrders; }
set { m_thisUsersOrders = value; }
}
}
When I create an instance of this object I need to populate the list variable When m_thisUsersOrders with an existing list of requests (from a viewstate).
MyOrders.RequestOrders = (List<RTODataEntryObjects.RTORequestOrder>)ViewState["vsMyOrders"];
When the page posts back, I cast the viewstate into a list of RTORequestOrder objects, and try to set the RequestOrders property, I get the message that the property or indexer cannot be assigned to. I have a "SET" accessor for the property.
All posts that I have read on this topic state that I need to modify scope in the application settings, but I am not sure how that applies here. I don't have any application settings set.
I am hoping someone can help me understand how I can populate the list from an existing list.
EDIT: Nico, Thanks for your response! Below is the full code from the code behind page. "MyOrders" and "lst" are essentially the same thing. When I am working with "lst" everything works the way that I want it to. The reason that I want to use the "MyOrders" object instead is because I have a method that returns the list as a datatable with only the fields I need to display. (I didnt' show that code because the issue appears to be with the "SET" accessor.) "lst" has the same signiture as the "MyOrders.RequestOrders". Why can I cast the the viewstate into the lst object, but not the MyOrders object?
EDIT: Grant, thanks for your response as well. I don't know how to set breakpoints for ASP pages... :(
public partial class Default3 : System.Web.UI.Page
{
RTODataEntryObjects.UserRequestOrders MyOrders = new RTODataEntryObjects.UserRequestOrders();
List<RTODataEntryObjects.RTORequestOrder> lst = new List<RTODataEntryObjects.RTORequestOrder>();
void Page_PreRender(object sender, EventArgs e)
{
if (ViewState["vsMyOrders"] == null)
{
NewDataGrid.DataSource = (RTODataEntryObjects.UserRequestOrders)ViewState["vsMyOrders"]; // code to show the data in the grid when page loading
}
}
protected void Page_Load(object sender, EventArgs e)
{
NewDataGrid.EnableViewState = true;
NewDataGrid.DataSource = (RTODataEntryObjects.UserRequestOrders)ViewState["vsMyOrders"];
NewDataGrid.DataBind();
}
public void btnSubmit(object sender, EventArgs e)
{
int id = Int32.Parse(TextBox1.Text); // dynamically getting the data from the frontend.
string name = TextBox2.Text; // dynamically getting the data from the frontend.
if (ViewState["vsMyOrders"] != null) // if the view state is already having data then can update the list and assign again to the viewstate later.
{
lst = (List<RTODataEntryObjects.RTORequestOrder>)ViewState["vsMyOrders"];
MyOrders.RequestOrders = (List<RTODataEntryObjects.RTORequestOrder>)ViewState["vsMyOrders"];
}
RTODataEntryObjects.RTORequestOrder thisOrder = new RTODataEntryObjects.RTORequestOrder(id, name, User.Identity.Name, System.Environment.MachineName);
lst.Add(thisOrder); //
MyOrders.AddNew(thisOrder);
ViewState["vsMyOrders"] = MyOrders;
NewDataGrid.DataSource = (IList<RTODataEntryObjects.RTORequestOrder>)ViewState["vsMyOrders"];
NewDataGrid.DataBind();
}
}
I have created a ListView from an Adapter, but I would like to select items, that gives an information about this item in new Activity.
That's my code:
protected override void OnListItemClick(ListView listview,
View view, int pos, long id)
{
var selectedvalue = sw_items[pos];
var i = new Intent(this, typeof(Activity1));
i.PutExtra("selectedvalue", selectedvalue);
StartActivity(i);
}
But i get this error:
MainActivity.OnListItemClick(Android.Widget.ListView, Android.Views.View, int, long)' is marked as an override but no suitable method found to override (CS0115)
MainActivity is an Activity
How can I solve this problem or is there any other way to do this within Activity
If you want to override OnListItemClick in MainActivity, the activity must be inhereited from ListActivity instead of plain old Activity.
Also, make sure the Listview in your xml is with the id "#android:id/list" (or list if it's in code).
There is a really nice guide you can follow: Populating a ListView With Data.
You need to remove the override, then somewhere in your setup you need to hook your method up to the click event on your list.
Normally this is done like this:
myList.OnClick += new ClickEventHandler(myMethodName);
But I haven't used monodroid so there may be some slight nuances.
Try the following:
#Override
protected void OnListClick(ListView listview, View view, int pos, long id) {
var selectedvalue = sw_items[pos];
var i = new Intent(this, typeof(Activity1));
i.PutExtra("selectedvalue", selectedvalue);
StartActivity(i);
}
Problem: Program flow is not going to the child class implementation of ValidateDynData when I call ValidateDynData in my parent class.
I create my instance of my class using reflection. When I invoke a method in the child class from another project, it winds up in the correct method in the child class (and not parent's same-name method), so it seems like that is set up correctly.
This is what the reflection part looks like in my other project/class:
**Note 3/7/2013: I added more info so you can get the general feel for this. It gets the number of boxes, loops thru the number of boxes, and for each box, creates a control and adds a tab to the form. This is the main CTool visual studio project and is a class in the project, which is a form. When I press a button on the form, with the info (selected) on which child class I'm going to be creating later, it goes to this method , CreatTabs():
cb = new CB();
int errValue = cb.FindUsbHid(ref HWndBoxID); //see how many boxes there are
if (errValue == 0 && HWndBoxID[0, 1] != 0)
{
for (int i = 0; i < cb.cbInfos.Length; i++)
{
if (controls[i] == null)
{
CB cb1 = new CB(); //need one for each box found or concurrent programming will fail
errValue = cb1.FindUsbHid(ref HWndBoxID); //need to do for each box to get all info
/////////////////////////////////////////
if (errValue == 0)
{
_assembly = Assembly.LoadFrom(programDll);
_type = _assembly.GetType("CrWriter.PC");
_objectInstance = Activator.CreateInstance(_type);
_parameters = new Object[] { cb1, programDll, templateArr, itsDll, cert, i, cb1.cbInfos[i].boxID };
controls[i] = new Control();
//The following lands in my child's GetPC method
//My parent also has a method called GetPC and that is called from the child.
//Then, most of the program flow is in the parent until I need to call ValidateDynData,
//discussed below
controls[i] = (Control)_type.InvokeMember("GetPC", BindingFlags.Default | BindingFlags.InvokeMethod, null, _objectInstance, _parameters);
controls[i].Dock = DockStyle.None;
this.Controls.Add(controls[i]);
TabPage newPage = new TabPage(string.Format("{0}:{1}", cb1.cbInfos[i].usbHandle, cb1.cbInfos[i].boxID));
Console.WriteLine("frmUserForm::CreateTabs - Making new tab with cb.cbInfos[i].usbHandle:" + cb1.cbInfos[i].usbHandle + " and cb.cbInfos[i].boxID:" + cb1.cbInfos[i].boxID);
InitializeControls(controls[i]);
tabCtrlMain.Size = controls[i].Size;
tabCtrlMain.Width += 20;
tabCtrlMain.Height += 100;
this.Width = tabCtrlMain.Width + 20;
this.Height = tabCtrlMain.Height + 50;
newPage.Controls.Add(controls[i]);
tabCtrlMain.TabPages.Add(newPage);
} //no err for this cb
} //controls not null
} //for all cbInfo's
}//if no err in general finding out how many cb's
this.ResumeLayout();
}
Since my Invocation of GetPC lands in the child class and not the parent, it must be created correctly. So I'm not sure why it's not landing in the correct ValidateDynData method. Maybe I need to cast my object to the programDll somehow. When I run the program and inspect the _objectInstance it could be a problem:
variable..................................................value
base: {GenericCrWriter.GenericPC} ......CrWriter.PC
baseInst: ................................................GenericCrWriter.GenericPC
But then, the _assembly is referring to Ko/PC and not Generic/GenericPC.
Also, my _assembly.GetType looks good. My Generic/parent doesn't have anything named CrWriter.PC
I'm trying to use the child class method instead of the parent class for some child class cases. For some reason, I get to the parent class method, but it never gets to the override in the child. Any ideas why? I've been referring to Calling child class method from parent
but it's not getting to the child's method.
In my PC.cs of the child class (Ko):
**Note 3/8/2013: PC.cs is in the Ko visual studio project. **this contains a form that is displayed
**Note 3/7/2013: This is a separate visual studio project named after the child, let's call it Ko. The important class here is PC.cs. It doesn't do much except pass data to the parent, provide it's custom textBoxes and their names, validate data entered later in the parent's form. Most of the flow is in the parent, otherwise. I'm adding GetPC, setProgramName, setDTF methods.
public partial class PC : GenericPC
{
String childDllName = ""; //I just added this recently but it doesn't seem useful
GenericPC baseInst = new GenericPC();
public Control GetPC(USB_Comm.CB cbInst, string dllSel, TemplateHApp.Templates.TEMPL[] templ, string dll, SC.SC.SITE c0, int slaveIndex, int BoxID)
{
childDllName = dll;
//call parent class methods
setProgramName();
setDTF();
ProcessDynData();
return baseInst.GetPC(cbInst, dllSel, templ, dll, cert0, slaveIndex, BoxID);
}
public void setProgramName()
{
Console.WriteLine("Ko did stuff");
//Update label on form
var f = new F(); //F is a class in child class containing more info on it
string temp = f.GetProgramName();
baseInst.setProgramName(temp); //this is displayed on parent's form
}
public void setDTF()
{
var f = new F();
string temp = f.DTF();
baseInst.setDTF(temp); //this is displayed on parent's form
}
private void ProcessDynamicData()
{
Console.WriteLine("Ko PC::ProcessDynamicData");
Label lbl_dynData0 = new Label();
Label lbl_dynData1 = new Label();
lbl_dynData0.Text = "AT .";
lbl_dynData1.Text = "VL .";
lbl_dynData0.Location = new Point(57, 25);
lbl_dynData1.Location = new Point(57, 45);
Label[] lbl_dynData_Arr = new Label[4];
lbl_dynData_Arr[0] = lbl_dynData0;
lbl_dynData_Arr[1] = lbl_dynData1;
TextBox tb_dynData0 = new TextBox();
TextBox tb_dynData1 = new TextBox();
tb_dynData0.Location = new Point(67, 25);
tb_dynData1.Location = new Point(67, 45);
tb_dynData0.Size = new Size(151,22);
tb_dynData1.Size = new Size(151, 22);
TextBox[] tb_dynData_Array = new TextBox[4];
tb_dynData_Array[0] = tb_dynData0;
tb_dynData_Array[1] = tb_dynData1;
PC pc = this; //Tried adding this to get past problem but it's not turned out useful
//I think the way I access parent class from child is the problem of why flow in
//parent class isn't reaching overridden method in child when called:
baseInst.addDynamicDataTextBoxes(tb_dynData_Array, lbl_dynData_Arr, childDllName, pc);
}
public override void ValidateDynData(TextBox[] tb_dynData_Array, ref int result)
{ //I added more info here, but it's probably too much info 3/7/2013
Console.WriteLine("Ko PC::ValidateDynData");
result = -610;
//AT
if ((Convert.ToInt16(tb_dynData_Array[0].Text) >= 1) && (Convert.ToInt16(tb_dynData_Array[0].Text) <= 99))
result = 0;
//VL
if (result == 0)
if ((Convert.ToInt16(tb_dynData_Array[1].Text) >= 69) && (Convert.ToInt16(tb_dynData_Array[1].Text) <= 100))
result = 0;
else
result = -610;
}
In my GenericPC.cs of the parent class:
**Note 3/8/2013: GenericPC is in the Generic visual studio project.
**Note 3/7/2013 When the child class calls the parent class to initialize important data, the parent class shows it's form and fields (I think resume layout shows it). Next, we enter data on the form, including Ko's custom data, then we hit a button on the form (btn_Lock_Config_Click) and it needs to process and validate it's data. I added more methods to get the feel for flow. There are a ton more methods in parent than child (not shown), including try/catch, etc.
//base
public partial class GenericPC : UserControl
{
//class variables (wave your hands..too much info)
public Control GetPC(USB_Comm.CB cbInstance, string dllSelected, TemplateHApp.Templates.TEMPL[] template, string dll, SC.SC.SITE c0, int slaveIndex, int boxID)
{
cb = cbInstance;
SlaveIndex = slaveIndex;
createControls();
itsDll = dll;
templateArr = template;
return this; //return the control for the control array
}
//called from child class
public void setProgramName(string name)
{
Console.WriteLine("Generic setProgramName slaveIndex:" + SlaveIndex);
lbl_Program_Name.Text = name;
}
//called from child class
public void setDTF(string theDTF)
{
Console.WriteLine("Generic setDTF slaveIndex:" + SlaveIndex);
lbl_Program_Name.Text += " ";
lbl_Program_Name.Text += theDTF;
lbl_Program_Name.Refresh();
}
public void addDynamicDataTextBoxes(TextBox [] tb_dynData, Label [] lblTitle, String childName, Object child)
{
childHasDynamicData = true; //somebody's knocking
itsChildName = childName; //child name isn't turning out to be useful here
itsChild = child; //child isn't turning out to be useful here
Console.WriteLine("Generic addDynamicDataTextBoxes slaveIndex:" + SlaveIndex);
//Display what child wants
for (int i = 0; i < tb_dynData.Length; i++)
{
//assumes calling code knows real estate and planned for it
gb_dynamicData.Controls.Add(lblTitle[i]);
gb_dynamicData.Controls.Add(tb_dynData[i]);
}
itsEnteredDynamicData = tb_dynData; //nothing entered yet
}
private void btn_Lock_Config_Click(object sender, EventArgs e)
{
int status = 1;
Console.WriteLine("Generic btn_Lock slaveIndex:" + SlaveIndex);
//it does some flagging and data checking, etc.
status = processDynamicData();
}
private int processDynData()
{
int returnCode = 0; //I'm setting it to desired value for example
//processes data, puts it into data arrays, etc,
if ((returnCode >= 0) && childHasDynamicData)
ValidateDynData(itsEnteredDynamicData, ref returnCode);
//start here for problem...it never calls child method, as intended
}
public virtual void ValidateDynData(TextBox[] tb_dynData_Array, ref int result)
{
Console.WriteLine("Generic::ValidateDynData passing off to child to validate special data");
}
Any ideas why it's not going to the child class implementation of ValidateDynData when I call ValidateDynData in my parent class? This is the only area in my code where I am trying to have a child class override a parent implementation, so I'm not sure if I'm doing something wrong?
I checked the correct version of Generic.dll is referenced in the child's project/class. I did a clean build in the child class. Any other binaries that should be checked? Is there something wrong with my reflection? Is there something wrong with my virtual/override use for ValidateDynData?
Update:
I've been looking at the code some more, and I get flow into the parent class by creating an instance of the parent/base class. So I think that's why I'm not getting into ValidateDynData that is overridden in the child class when I call it in parent. Is there another way to get to the parent's method without creating an instance of the parent?
GenericPC baseInst = new GenericPC();
return baseInst.GetPC(cbInst, dllSel, templ, dll, cert0, slaveIndex, BoxID);
**Update 3/7/13:
It's also possible that the problem is that I press a button on the parent's form which starts a new thread and by doing this, it doesn't know about child class, so that's why flow doesn't get to child when I call ValidateDynData method.
Short answer: Just delete all that awful code and start over.
Longer answer:
// (1)
public partial class PC : GenericPC
{
// (2)
GenericPC baseInst = new GenericPC();
public Control GetPC(…)
{
…
// (3)
return baseInst.GetPC(cbInst, dllSel, templ, dll, cert0, slaveIndex, BoxID);
}
public override void ValidateDynData(TextBox[] tb_dynData_Array, ref int result)
{
// (4)
…
}
}
Comments to marked lines of code:
At this point you declare PC as a descendant of GenericPC. So far so good.
Here you declare and instantiate a completely disparate instance of GenericPC which has nothing to do with the instance of PC you are working with.
You call GetPC, a method of an instance of PC, which in turns call GetPC in that completely disparate instance of GenericPC; nothing in common with the original PC instance!
Finally, you expect control flow to end up the original PC instance; but that won't ever happen when, effectively, you all the time call methods of some silly GenericPC instance!
My recommendation is reading a book about object-oriented programming, that provides samples in C#. It seems you are even missing the point of inheritance, one of the basic concepts in OOP.
To fix it, you need to remove the declaration of baseInst, and replace all calls to baseInst's methods with the base keyword. Then your code will actually call methods declared in the ancestor class within the same instance. Also most methods shall be declared as virtual in GenericPC and you have to override them in PC.
public partial class PC : GenericPC
{
public override Control GetPC(…)
{
…
return base.GetPC(cbInst, dllSel, templ, dll, cert0, slaveIndex, BoxID);
}
public override void ValidateDynData(TextBox[] tb_dynData_Array, ref int result)
{
…
}
}