How to add second column to a listBox component?

ken76

Member
Joined
Nov 15, 2018
Messages
23
Programming Experience
5-10
For the moment I can only get the subfolders name of C:\Backup folder to the first column of the listBoxComputer.
Have do I get also the last written date of subfolders to the second column of the 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;         
}
 
Last edited by a moderator:
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.
 
Back
Top Bottom