Thank you first for taking the time to read, I know I'm N00B but a N00B lost in code. This is a school assignment and I can turn in the console app, because it works, but I would like to make this look pretty in a WinForm app.
Core problem I need to use LINQ to query and display a collection of objects based on the filter, this I can do in a Console Appliction.
When I tried to make it look pretty in a Winform the array is not accessable from the buton click event. Pretty sure I am just creating the objects in the wrong way. I suck with WinForm apps.
:: My namespaces all match.
:: This code will correctly run the LINQ query in a consol so I know that the var sortDescription.. is probably good.
First there is this code which creates my array of objects:
{
public partial class DisplayForm : Form
{
public DisplayForm()
{
InitializeComponent();
QueryClass QClasses = new QueryClass();
Invoice[] invoiceItems = new Invoice[8];
invoiceItems[0] = new Invoice(83, "Electric sander", 7, 57.98M);
invoiceItems[1] = new Invoice(24, "Power Saw", 18, 99.99M);
invoiceItems[2] = new Invoice(7, "Sledge Hammer", 11, 21.50M);
invoiceItems[3] = new Invoice(77, "Hammer", 76, 11.99M);
invoiceItems[4] = new Invoice(39, "Lawn Mower", 3, 79.50M);
invoiceItems[5] = new Invoice(68, "Screwdriver", 106, 6.99M);
invoiceItems[6] = new Invoice(56, "Jig saw", 21, 11.00M);
invoiceItems[7] = new Invoice(3, "Wrench", 34, 7.50M);
}
private void queryA_Click(object sender, EventArgs e)
{
var sortDescription =
from element in invoiceItems
orderby element.PartDescription
select element;
foreach (var element in invoiceItems)
{
displayHere.AppendText(element.ToString() + Environment.NewLine);
}
}
.... I have tried this in both the Publc DisplayFrom() block and created my own block netiher works.
Now the error and my problem.
:: When in some test codes I utilize the method of display it works, the AppendText...
:: The ojbect called invoiceItems is in the standard Winform public DisplayForm() right below the initialzeComponent(). And the button object can't see the object 'invoiceItems'. I am guessing it's because the scope of the two objects is my problem.
:: I have tried creating my array of objects in a public void class but that didn't work either (Told you I was a N00B)
How do I get the objects in the Button Action to see the instatiated array object of items?
Lastly, any help is appreciated and I want to thank you in advance. Yes I have been googleing for hours and gave up so I am outside weeding.
Scott