C# 使 ListView 在垂直方向可滚动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2309046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Making ListView scrollable in vertical direction
提问by Ravisha
I am using a System.Windows.Forms.ListView
with checkboxes = true
.
I can see that when the list items are more than what can fit, I get a horizontal scroll bar. I tried to find any properties to change scroll bar orientation.
Is there any way to make it scrollable in vertical direction?
我正在使用System.Windows.Forms.ListView
与checkboxes = true
. 我可以看到,当列表项超出可容纳范围时,我会得到一个水平滚动条。我试图找到任何属性来更改滚动条方向。有没有办法让它在垂直方向上滚动?
采纳答案by NileshChauhan
You need to Set
你需要设置
Listview1.Scrollable = true;
Listview1.View = View.Details
This will only work correctly if you have added some columns in your Listview1, So add a dummy column. like,
如果您在 Listview1 中添加了一些列,这只会正常工作,因此添加一个虚拟列。喜欢,
ColumnHeader header = new ColumnHeader();
header.Text = "";
header.Name = "col1";
listView1.Columns.Add(header);
回答by Dave
The ListView should also display a vertical scrollbar automatically if you've got enough items in the collection (i.e. more than can be displayed on the ListView currently).
如果集合中有足够多的项目(即超过当前 ListView 可以显示的项目),则 ListView 还应自动显示垂直滚动条。
回答by Asad
回答by Neil Barnwell
You can't change the scroll bar orientation, per sé.
你不能改变滚动条的方向,本身。
You get a vertical scrollbar if you have items that go off the bottom of the listview, and a horizontal scrollbar if you have items that go off the right-hand side of the listview.
如果您的项目超出列表视图的底部,您将获得一个垂直滚动条,如果您的项目超出列表视图的右侧,您将获得一个水平滚动条。
So if you want to control the scrollbars, you actually do this by controlling the content. Personally I only ever use ListViews in Detail mode, but to take that as an example, you would make sure that your column headers are sized such that they all fit in the horizontal space.
所以如果你想控制滚动条,你实际上是通过控制内容来实现的。就我个人而言,我只在 Detail 模式下使用 ListViews,但举个例子,你需要确保你的列标题的大小都适合水平空间。
回答by Sepehr Shojaee
I think the only way to force the ListView scroll vertically and view items as "Title" mode, is this :
我认为强制 ListView 垂直滚动并将项目视为“标题”模式的唯一方法是:
ListView.View = View.Details;
ListView.HeaderStyle = ColumnHeaderStyle.None;
and add JUST ONEColumn
并添加仅一列
回答by Danil
You'll need
你需要
listView1.View = System.Windows.Forms.View.SmallIcon;
listView1.View = System.Windows.Forms.View.SmallIcon;
Then your control will have vertical scrollbar and behaviour pretty much the same like View.List
然后您的控件将具有垂直滚动条,行为与 View.List 几乎相同