如何将第二列添加到listBox组件?

ken76

成员
已加入
2018年11月15日
留言内容
7
编程经验
5-10
目前,我只能将C:\ Backup文件夹的子文件夹名称添加到listBoxComputer的第一列。
我是否也将子文件夹的最后写入日期发送到listBoxComputer的第二列?

C#:
private string rootDir = @"C:\Backup";       

private void FormView_Load(object sender, EventArgs e)        {                     
   List<string> ls = Directory.GetDirectories(rootDir).Select(Path.GetFileName).ToList();           
    ls.Sort((a, b) => -1 * a.CompareTo(b));       
    listBoxComputer.Sorted = false;           
    listBoxComputer.DataSource = ls;           
    listBoxUser.SelectedIndex =-1;         
}
 
由主持人最后编辑:

金西尼

C#论坛主持人
工作人员
已加入
2011年4月23日
留言内容
3,566
地点
悉尼,澳大利亚
编程经验
10+
You don't, because a ListBox doesn't have multiple columns. Not in the sense that you are talking about, anyway. By default, if a ListBox contains more items than it can display vertically, they simply overflow vertically and cannot be seen. If you set MultiColumn to True, the excess items will overflow into an additional column. It's still just a single list though. If you want to display multiple columns per record then a ListBox is not the control for you. You should use a ListView or DataGridView instead. The alternative is to write your multiple values per record into a single item in the ListBox and use padding to simulate multiple columns. For that to work, you need to use a fixed-width font.
 
最佳 底部