C#DataGridView和ImageLists

编程入门 行业动态 更新时间:2024-10-17 09:38:57
本文介绍了C#DataGridView和ImageLists的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好, 我的第一篇文章!对我好一点:P 我有一个由三个表组成的小型SQL CE数据库.每个表都填充到一个单独的DataGridView中,一旦完成,一个简单的foreach循环就会遍历一个图像列表.每个DataGridView一个,并将主键与ImageList的索引匹配.这将使用正确的图像填充适当的列.这里没有太多数据:200行,每个表10列. 现在,我不喜欢使用imagelist中存储的图像的索引,因为如果从表中删除一项,我的主键将不匹配相应的图像并显示不正确的图像.简化此方法的最佳方法是什么?我正在尝试找到一种简单的方式来稍后更新和删除数据,并使适当的图像与表中的内容相对应.我已经尝试过向表中添加一个带有文件名的新列,然后根据图像列表中的文件名加载图像,这似乎可以正常工作.只是在寻找想法!任何帮助表示赞赏.感谢

Hello, My First Post! Be easy on me :P I have a Small SQL CE Database that consists of three tables. Each Table gets filled into a seperate DataGridView, once this is completed a simple foreach loop iterates through an imagelist(s). One per DataGridView and matches the Primary Key to the Index of the ImageList. This populates the appropriate columns with the correct image. There is not much data here: 200 Rows, 10 columns per Table. Right now i''m not liking using the index of the image stored in the imagelist because if I remove an entry from the table my primary key does not match the appropriate image and display the incorrect one. Whats the best way to simplify this? I''m trying to achive a simple way to update and remove data later on and have the appropriate image correspond with what is in the table. I have experimented with adding a new column to the table with a file name and then loading the images based on the filename in the imagelist which seems to work fine. Just looking for ideas! Any help is appreciated. Thanks

推荐答案

我的第一个想法是:图像从哪里来构建图像列表?必须从某个地方建立了映像列表……是某个地方的某种持久性存储(文件系统或数据库?). 如果是这样,那么该持久性存储将具有可用于映像的某些唯一标识符,而不是映像列表. 但是,让我们假设图像列表是动态构建的,并且还没有持久性存储. 在.Net中,映像是引用类型-这意味着您可以以最小的内存开销(只是引用的大小)将它们存储"在多个内存结构中.因此,...在累积图像时,首先将它们添加到集合中(也许是List< Image>),然后将它们添加到ImageList中.同样,建立一个字典,将其在图像列表中的位置与在幕后"列表中的位置相关联. (实际上,如果您做对了,您可能会发现您既不需要字典又不需要列表;我在设计之路上走得还远远不够). 现在,(a)在列表中存储图像的索引(或其他),以及(b)从ImageList中删除图像时,您不将它们从列表中删除.列表...因此,除非您准备好清除整个世界并重新开始,否则对列表的引用永远不会过时. HTH. 克里斯 My first thought is: Where do the images come from that build the image list? Something must have built the image list from somewhere ... was that somewhere a persistent storage of some kind (file system? database?). If so, then that persistent storage will have some unique identifier for the images that you can use instead of the image list. Lets assume, however, that the image list is built dynamically and there''s no persistent storage (yet). In .Net images are reference types - which means you can ''store'' them in multiple memory structures with minimal memory overhead (just the size of the reference). So... As you accumulate images, add them first to a collection (List<Image>, perhaps) and second add them to the ImageList. Also, build a dictionary that correlates their position in the image list to their position in the ''behind the scenes'' list. (Actually, if you do it right, you may find you don''t need both the dictionary and the list; I''ve not gone far enough down the design road to know). Now, (a) you store in your data grids the index (or whatever) of the images in the list, and (b) when you remove images from the ImageList, you do not remove them from the list... so references to that list never get stale until you''re ready to clear the whole world and start over. HTH. Chris

更多推荐

C#DataGridView和ImageLists

本文发布于:2023-11-10 16:20:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575872.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:DataGridView   ImageLists

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!