简体   繁体   English

Visual Studio 2012 c#ListView问题-有点奇怪

[英]Visual Studio 2012 c# ListView issue - kinda strange one

I'll try to explain best I can. 我会尽力解释。

I have a ListView in visual studio c# form, with a function to populate it. 我有一个Visual Studio c#格式的ListView,其中包含一个填充它的函数。 When I recently tried to update that ListView by adding a column, it just showed only previous columns populated. 当我最近尝试通过添加列来更新该ListView时,它只显示了以前填充的列。 Then, for an even greater surprise. 然后,带来更大的惊喜。 When I changed function text in order to populate "old" columns a bit differently just to make sure it works (like, adding string "test string" to a column populating string) nothing happened - it just stayed the old way. 当我更改函数文本以稍有不同地填充“旧”列时,只是为了确保它能正常工作(例如,将字符串“ test string”添加到填充列的列中),什么都没发生-它只是保留了旧方法。 After that, I completely erased population function body, leaving nothing inside brackets - and listview was still populated with data, like it called the original version of function, even though I had just erased it completely. 之后,我完全擦除了填充函数主体,括号内没有留下任何内容,即使我刚刚完全擦除了函数,列表视图仍然填充了数据,就像它称为函数的原始版本一样。 Left me puzzled. 让我感到困惑。 Failed to google anything similar. 无法通过Google进行类似操作。 More funny stuff - i put a MessageBox into function body just to make sure that "new" function is called at all. 更有趣的东西-我将MessageBox放入函数主体只是为了确保“新”函数被调用。 And yes, MessageBox is being displayed so it actually accepts that change of function. 是的,正在显示MessageBox,因此它实际上接受该功能更改。 Code to show it: 显示代码:

private void populateMissionList() 
           {
        this.listView1.Items.Clear();
        List<MisijaDTO> misije = MisijaDAO.ocitajSve();

        foreach (MisijaDTO mission in misije) 
        {


            string idmisije = "" + mission.Id;
            ListViewItem stavka = new ListViewItem(idmisije);
            stavka.SubItems.Add(mission.Naziv);  // "old" column
            stavka.SubItems.Add(mission.Datum + " test string"); //"old" column, but won't show newly added "test string"
            if (mission.Uspjesna){
                stavka.SubItems.Add("Uspješna"); // "new" column, won't be shown... 
             MessageBox.Show("282 true"); //... but this text box is shown
            }
            else {stavka.SubItems.Add("Neuspješna");MessageBox.Show("282 false");}
            listView1.Items.Add(stavka);

        }
    }

My best guess why this happened - I have previously cut that listView from the form, pasted it onto another form (which I used as a backup), and later copied it from backup form and pasted it back onto original form. 我最好的猜测是为什么发生的-我之前已经从表单中剪切了该listView,将其粘贴到另一个表单(用作备份)上,然后从备份表单中复制了它,然后将其粘贴回到了原始表单中。 I suppose ListView somehow got stuck with the old function definition, but I wasn't able to solve it. 我想ListView某种程度上被旧的函数定义所困扰,但我无法解决它。 Tried to: rename ListView, rename population function, clean solution, rebuild solution, close and reopen Visual Studio... nothing helped. 尝试执行以下操作:重命名ListView,重命名填充函数,清理解决方案,重建解决方案,关闭并重新打开Visual Studio ...无济于事。 It's not database problem either, because it will read new database imports into ListView, but limited to "old" set of columns like it won't recognize ListView that I pasted back. 这也不是数据库问题,因为它将新的数据库导入读取到ListView中,但仅限于“旧”列集,因为它无法识别我粘贴回的ListView。 ListView name remaine same after cut/paste/copy/paste, so I guess that's not issue either. 剪切/粘贴/复制/粘贴后,ListView名称保持不变,因此我猜也没有问题。

If you need some more information, I'd be glad to provide. 如果您需要更多信息,我们将很高兴为您提供。

Look in the .designer.cs file where the Column Collection is populated. 在.designer.cs文件中查找填充了“列集合”的位置。 You probably need to add another column into that.... 您可能需要在其中添加另一列...。

I owe A BIG apologie to anyone who spent their precious time reading this topic. 对于那些花费宝贵时间阅读本主题的人,我深表歉意。 There isn't any bug or something, but I overlooked some piece of code that was related to my function and that populated list the old way separately. 没有任何错误或其他东西,但是我忽略了一些与我的函数相关的代码,并且分别填充了旧方法。 Seems everything works just fine right now. 似乎现在一切正常。

Good side of this is that I signed up for Stack Overflow finally :) 好的一面是我最终注册了Stack Overflow :)

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

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