繁体   English   中英

C#在两个列表视图之间进行通信

[英]C# communicating between two listviews

我有一个框架。 在其中保留两个ListViews。 现在,基于第一个列表视图中选择的项目,我执行一些操作并填充第二个列表视图的内容。

我是C#的新手,无法理解什么是更新事物的最佳方法。 让我按代码显示。

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 ListB ();
f.Add (a);
f.Add (b);

// Now how do I get the event of selectionChanged in ListA to affect the contents of ListB

}

如果您需要更多详细信息,请告诉我。 谢谢。

您必须注册到第一个listView的SelectedIndexChanged事件。 在此事件处理程序中,实现基于选择填充第二个listView的逻辑(请查看eventArgs对象)

我不了解您使用的是什么技术(winform?wpf?ASP?),但这是winforms的示例:

http://msdn.microsoft.com/zh-CN/library/system.windows.forms.listview.selectedindexchanged.aspx

我正在使用mono的ncurses库,但没有发生此事件。 因此,解决方案是让我创建自己的Event及其EventHandler。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM