vb.net 如何显示 ListBox / ListView 列对齐
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18969882/
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
How to Display ListBox / ListView Column Alignment
提问by ed209
I'm trying to Display ListBoxes / ListViews as 2 Columns with the first one left aligned and second one right aligned.
我正在尝试将 ListBoxes / ListViews 显示为 2 列,第一列左对齐,第二列右对齐。
I'd think this would be super easy and it probably is, but every time I google it I can't come up with what I need. I need to display either a listview or listbox (doesn't matter which) with two columns, the first of which is left aligned and second of which is right aligned.
我认为这会非常容易,而且可能是这样,但每次我用谷歌搜索它时,我都找不到我需要的东西。我需要显示带有两列的列表视图或列表框(与哪个无关紧要),其中第一列左对齐,第二列右对齐。
Also will need to know how to populate it. I have tried quite a few different approaches, but can't seem to get it right.
还需要知道如何填充它。我尝试了很多不同的方法,但似乎无法做到正确。
回答by varocarbas
Here you have the code you are looking for:
在这里你有你正在寻找的代码:
With ListView1
.View = View.Details
.Columns.Add("Column1")
.Columns.Add("Column2")
.Columns(0).TextAlign = HorizontalAlignment.Left
.Columns(1).TextAlign = HorizontalAlignment.Right
Dim item As New ListViewItem(New String() {"row1-col1", "row1-col2"})
.Items.Add(item)
End With

