这是与收藏有关的问题 [英] here is the question relatede to the Collections

查看:61
本文介绍了这是与收藏有关的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class ThumbItem
    {
      
       public  int x, y, height, width;
       public string sz_Original_Image_filepath;
       public bool b_state;
       public string sz_chkImage_filepath;
       public Bitmap bt_Image;

       public ThumbItem()
       {
           int x = 0, y = 0, height = 100, width = 100;
           string sz_Original_Image_filepath = null;
           bool b_state = false;
           string sz_chkImage_filepath = null;
           Bitmap bt_Image = null;
       }
   } 
       

    class Image_Thumbnail
    {
       public ThumbItem[] thumbitem ; 
       public  Array Items = new Array();
                     
       public void DrawItem() 
        {
        //
        }

       public void RefreshItem()
        {
      
        //
        
        }         
     
    } 



现在的问题是我想在listview项目的seletedindex处将b_state的值设置为true ..我已经确定了listview中选择了哪个索引,并基于该索引我想更改b_state的状态...考虑表示item集合包含ThumbItem类型的对象..
现在我认为问题非常清楚...



Now the question is I want to set the value of b_state to be true at seletedindex of the listview items ..I have mentained which index is selected in the listview and based on that index i want to change the state of b_state ...considering that the items collection is holding ThumbItem type objects ..
Now i think the question is very much clear ...

推荐答案

简短的答案是:不好的主意.干燥的原则( http://en.wikipedia.org/wiki/Don%27t_repeat_yourself [ http://en.wikipedia.org/wiki /Invariant_%28computer_science%29 [ ^ ]):所选项目的b_state值为true,对于未选择的项目,该值应为false.为此,您将需要处理控件的选择事件并调整数据项中的值.这意味着不变量会保留一段时间,但并非所有时间都保持不变,这使它变得不可靠.

我什至没有讨论过将数据层与UI隔离的问题.在这个话题上浪费了很多词,但似乎很明显.

您的问题不是问题.您说我想要",仅此而已.您遇到的问题和解决问题的方法就是停止想要坏事.我很确定不使用您的要求就能更好地实现您的目标.如果您想讨论它,请解释您的最终目标,请使用上面的改善问题".

—SA
Short answer is: bad idea. This would be a violation of the D.R.Y. principle (http://en.wikipedia.org/wiki/Don%27t_repeat_yourself[^]). It also violates the principle of isolation of data layer from UI. These violations is invitation for trouble.

The fact of selection is already expressed in the control. The data integrity requires the following invariant (http://en.wikipedia.org/wiki/Invariant_%28computer_science%29[^]): the selected item''s b_state value is true and for the unselected item this value should be false. To achieve that, you will need to process selection events of controls and adjust the values in data items. It means that the invariant holds for some period of time, but not all the time, which makes it unreliable.

I don''t even discuss the isolation of data layer from UI. Many words was wasted on this topic, but it seems to be pretty obvious.

Your question is not a question. You say "I want", that''s it. You problem and the solution of your problems is to stop wanting bad thing. I''m pretty sure your goals can be met much better without using your requirements. If you want to discuss it, explain your ultimate goals, use "Improve question" above.

—SA


((ThumbItem)list.SelectedItem).b_state = ...


像这样吗?

您是否了解ThumbItem构造函数仅设置局部变量而不设置类级别字段?您永远不要直接公开字段,使用属性.


Like this??

You do understand the ThumbItem constructor is only setting local variables not the class level fields? You should never expose fields directly, use properties.


这篇关于这是与收藏有关的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆