Currently I'm creating a list in "Form1" pretty much this:
//
//
this.Shortlist = new System.Collections.Generic.List
this.ShortlistIndex = (int)binaryReader.BaseStream.Position;
for (i = 0; i < (int)shortlistnum; i++)
{
Shortlist item2 = new Shortlist(binaryReader);
this.Shortlist.Add(item2);
}
binaryReader.Close();
The Shortlist class is:
The Shortlist class is:
public class Shortlist
{
public string Name;
public string Nation;
public string NationalityName;
public int Age;
public Shortlist()
{
}
public Shortlist(System.IO.BinaryReader reader)
{
this.Name = reader.ReadString(128).Replace("\0", string.Empty);
}
}
All works fine..I then call another function (still in Form1) which joins this list with another list to create a 3rd list (and bind it to a listview):
private void Populate(object sender, EventArgs e)
{
var userlist = (from Item1 in Shortlist
join Item2 in People
on Item1.Name equals Item2.FullName
into grouping
from Item2 in grouping.DefaultIfEmpty()
select new
{Item2.FullName
,Item2.Age
,Item2.CountryName
,Item2.Nationality
}).ToList();
this.fastObjectListView3.SetObjects(userlist);
}
Again, happy with this, all is ok..
In "Form2" I have a button and when clicked I want to pass a pre-defined string/item/value/object...whatever you call it and add it into this.Shortlist (In Form1) and then my "Populate" function called to repopulate & bind my 3rd list.
I can't seem to work out how to add across classes..any help..Vulpes :p would be great
I can't seem to work out how to add across classes..any help..Vulpes :p would be great
VulpesPosted May 14, 2013, 6:36 PM
VulpesPosted May 15, 2013, 5:52 AM
In the more general case, where you wanted to identify a particular ShortList object by Name property and then remove it from the List, you could use LINQ like this:
{
f1.Remove(itemToRemove);
}
Jay SPosted May 15, 2013, 5:43 AM
Is there an easy/simple way to remove from the list..
So lets say I've added "John" from shortlist.
Is there a way to remove "John" and re-call populate() ?
Edit..maybe:
f1.Shortlist.Remove(sl); ?
VulpesPosted May 15, 2013, 4:36 AM
Jay SPosted May 15, 2013, 3:59 AM
One thing I'm not sure about is:
Specifically:
If I'm adding "sl" how can I set that value before the add?
E.g. I want to add into the list the name "John"
Abhishek SurPosted May 15, 2013, 1:08 AM
From form2 call,
Form1.ShortList.Add(whatever);
And then call,
Form1.Populate();