为什么将调用移动到在窗体的load事件中加载listview的方法会影响listview的显示? [英] Why would moving a call to a method that loads a listview in the form's load event affect the listview's display?

查看:62
本文介绍了为什么将调用移动到在窗体的load事件中加载listview的方法会影响listview的显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不确定该帖子标题是否有意义 - 在一篇文章中很难说。

在表格(.NET CF 2.0,顺便说一句)上,我有一个列表视图标签控件。列表视图有两列,用于显示一个人的徽章编号和他分配的系列代码,在运行时,这些代码最初是逐行填充的(单击"添加"按钮,另一个表单加载,分配一系列代码在那里,返回主窗体,在列表视图中添加一个新行)。然后,用户点击"保存"按钮。创建按钮和dB记录,其中包含有关列表视图中所有行的信息。这很好 - 没有关于我到目前为止所描述的问题。 (请参阅此图片了解它的样子:http://i36.tinypic.com/5d6hz5.jpg)。

但是,用户也可以选择一个选项来查看保存到数据库中的项目记录。这是通过在表单的加载事件中自动填充表单及其选项卡控件和列表视图来完成的。在那里调用一个方法来设置最终填充列表视图的一系列其他方法。

当用户添加一行时,我使用基本相同的代码向listview添加一行当它从数据库中填充时:

Not sure if that thread title makes sense - kinda hard to say in one sentance.

On a form (.NET CF 2.0, by the way), I have a listview that is on a tab control. The listview has two columns and is used to show a person's badge number and a series code he's assigned to, which, at run time, is initially populated line by line (click "Add" button, another form loads, assign a series code there, return to the main form, add a new line to the list view). Then the user clicks a "Save" button and a dB record is created with information about all of the lines in the listview. This works fine - no issues regarding what I've described so far. (See this pic for what it looks like: http://i36.tinypic.com/5d6hz5.jpg).

However, the user can also choose an option to view those items saved to the database record. This is done by populating the form and it's tab control and the listview automatically in the form's load event. There is a call to a method there that sets off a series of other methods that eventually populates the listview.

I use essentially the same code to add a line to the listview when it's added by a user as when it's populated from the database:

' Adding a new list item
Dim sSeriesItem() As String = {objWOWRec.BadgeNumber, m_objPickCodeSeries.Series}
Dim listItem As MyListViewItem = New MyListViewItem(sSeriesItem, objWOWRec)

m_lstMBH2BadgeSeries.Items.Add(listItem)


查看此图片,了解listview在填充时的样子来自数据库:http://i38.tinypic.com/33licgj.jpg

我把它缩小到.Add行,导致listview的列不显示在上面的图片中。当用户逐个添加它们时不会发生这种情况,但只有在页面加载事件中从数据库中填充列表视图时才会发生这种情况(通过一系列其他方法最终逐步实现到方法加载此列表视图)。

MSDN在此处说:"要调整列中最长项目的宽度,请将 Width 属性设置为-1。要自动调整到列标题的宽度,请将 Width 属性设置为-2。"我试过 - 并设置我自己的宽度 - 在对象的属性中,甚至在填充方法中的.Add行之后。

我发现的真的奇怪的事情,但是如果只是调用listview的话在表单加载事件的最后填充方法然后listview显示正常。

我现在可以保留它(在表单加载事件中显式调用listview填充方法,但我需要把它归还它所属的地方 - 在我用于表格的常规装载结构中。

如果有人可以帮助我,我会非常感激!

< hr class ="sig"> fu cn rs ths u cn gt gd jb n cmptr prgrmmng

See this pic for what the listview looks like when it's populated from the database: http://i38.tinypic.com/33licgj.jpg

I've narrowed it down to the .Add line that causes the listview's columns to not show as in the above pic. That doesn't happen when they're added one by one by the user, but it only happens when the listview is populated from the database in the page load event (via a series of other methods that finally work their way down to the method that loads this listview).

MSDN says here: http://msdn.microsoft.com/en-us/library/system.windows.forms.columnheader.width.aspx that "To adjust the width of the longest item in the column, set the Width property to -1. To autosize to the width of the column heading, set the Width property to -2." I tried that - and setting my own widths - both in the object's properties and even after the .Add line in the populating method.

The really odd thing that I found out, though is that if simply call the listview's populating method at the very end of the form load event then the listview displays fine.

I can leave it as is for now (calling the listview populating method explicitly in the form load event, but I will need to get it back where it belongs - in the regular loading structure I have for the form.

I'd greatly appreciate it if someone could assist me on this!


f u cn rd ths u cn gt a gd jb n cmptr prgrmmng

推荐答案



是问题你没有看到任何列标题,或者数据没有显示我会问,因为你提供的截图没有显示任何数据,是故意的吗?

他们确实显示缺少列标题徽章和名称,是这个问题?

感谢

保罗·迪斯顿
Hi,

Is the problem that you are not seeing any column headings, or that data is not displaying when it should?

I ask, because the screen shots you provided do not show any data, is that intentional?

They do show a lack of column headings Badge and Name, is this the problem?

Thanks

Paul Diston


这篇关于为什么将调用移动到在窗体的load事件中加载listview的方法会影响listview的显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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