C# communicating between two listviews
I have a Frame. Inside this I keep two ListViews. Now based on the item selected in the first listview, I do some operations and populate the contents for the second listview.
I am new to C# and not able to understand what is the best way to update things. Let me show by code.
Class ListA : IListProvider
{
List<string> items = new List <string> ();
void selectionChanged ()
{
//view.Selected gives the selected item index in the list
}
}
class ListB : IListProvider
{
List<string> items = new List <string> ();
}
Class Shell
{
Frame f = new Frame ();
ListA a = new ListA ();
ListB b = new开发者_JAVA百科 ListB ();
f.Add (a);
f.Add (b);
// Now how do I get the event of selectionChanged in ListA to affect the contents of ListB
}
Please let me know if you need more details. Thanks.
You must to register to SelectedIndexChanged event of 1st listView. In this event handler implement a logic of populating 2nd listView based on selection (look at eventArgs object )
I dont understand what technology you are using (winform ? wpf ? ASP ? ) but here is example for winforms :
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.selectedindexchanged.aspx
I was using mono's ncurses library and it did not had this Event. So the solution was for me to create my own Event and its EventHandler.
精彩评论