ListView 与 ListBox 的多列使用 [英] ListView vs. ListBox for multiple column usage

查看:36
本文介绍了ListView 与 ListBox 的多列使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为我的应用程序的 GUI 苦苦挣扎.我很难确定 ListBox 还是 ListView 更适合"数据的多列表示.

I am currently struggling with the GUI of my application. I have a hard time figuring out whether the ListBox or ListView is more "suitable" for multi-column representation of data.

我更喜欢干净"的代码,不会太混乱而难以弄清楚,因为意大利面条式代码和黑客方法可能会导致混乱.

I prefer "clean" code that is not too confusing to figure out, as spaghetti code and hacking methods can lead to confusion.

ListBox 和 ListView 如何处理多列?

How do both ListBox and ListView handle multiple columns?

推荐答案

在这种情况下,DataGridView 肯定没有问题.

There's certainly nothing wrong with a DataGridView in this scenario.

示例:

class Car
{
    public string Make { get; set; }
    public string Model { get; set; }
    public int Year { get; set; }
}

将数据加载到DataGridView

private void LoadData()
{
    List<Car> cars = new List<Car>()
    {
       new Car() { Make = "Subaru", Model = "Impreza", Year = 2005 },
       new Car() { Make = "Ford", Model = "Mustang", Year = 1984 }
    };

    dataGridView1.DataSource = cars;
}

当然,从这里开始事情会变得更复杂,但如果您只是想以表格方式显示数据......这很简单.

Of course, from here things can get more complicated, but if you simply want to display data in a tabular fashion... it's pretty simple.

这篇关于ListView 与 ListBox 的多列使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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