且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何匹配列表视图中的项目和图像列表中的图像

更新时间:2023-12-05 17:33:28

看看 ObjectListView [^ ]
这是文章更易于使用ListView [自定义绘画 [
Have a look at ObjectListView[^]
Here is an article A Much Easier to Use ListView[^].

If you really want to use the standard listview, have a look at custom painting[^].

Best regards
Espen Harlinn


您的英语还不错;我希望其他成员可以用一种清晰的语言发布他们的问题,而不会出现难看的拼写错误.但是,您的问题看起来是人为的.您首先将一些不匹配的数据放入控件中,之后又想匹配项目.为什么?

您应该执行以下操作:您需要将数据层与UI分开.当您想在数据中找到某种关系的实际数据元素时,可以在数据中找到它,而不是在UI控件中.

对于您的问题,您可以执行以下操作之一:1)不要将图像和文件名分开存储,使用包含两者的结构列表进行处理; 2)创建一个字典,例如由文件名索引的System.Collection.Generic.Dictionary<string, Image>(例如,在用作键之前将它们大写);即可通过文件名快速进行O(1)数据搜索(如果您不知道"Big O"符号,请阅读 ^ ]).

获得正确的数据模型后,请考虑将数据绑定到UI.在最简单但最灵活的情况下,它可能只有两种方法:从数据填充UI并从UI更新数据,但是有可能,您可能需要更复杂的UI行为,但是仍然可以使用数据模型来完成,不只是UI或UI中的数据.基于这些理由,还必须认真地重新考虑您的UI设计.我不知道您的细节,但是如果您改变方法,进行一些开发但遇到问题,请提出进一步的问题.我很有可能会提供帮助,其他专家也可能会提供帮助.

—SA
You English is fine; I wish other members could post their question in such a clear language free from ugly spelling mistakes. However, your problem looks artificial. You put some unmatched data in controls in first place and later wants to match items. Why?

You should do the following: you need to separate your data layer from UI. When you want to find anything in data, an actual data element of some relationship, find it in data, not in the UI control.

As to your problems, you can do one of the following: 1) do not store images and file names separate, work with a list of structures containing both; 2) create a dictionary, such as System.Collection.Generic.Dictionary<string, Image> indexed by the file names (say, lo-case them before using as a key); that will give you a fast O(1) search of data by the file name (if you don''t know "Big O" notation, read http://en.wikipedia.org/wiki/Big_O_notation[^]).

After you got a proper data model, think about data binding to your UI. In a simplest but most flexible case, it could be as simple as two method: population of UI from data and update data from UI, but chances are, you might need more complex UI behavior, but nevertheless, do it using the data model, not just UI or data in UI. On these grounds, also critically re-think you UI design. I don''t know your detail, but if you change your approach, do some development but face with problems, ask your further questions. Most likely I would be able to help, other experts will probably help, too.

—SA