我正在开发一个项目,在该项目中我将自定义列表绑定到数据网格。我认为我当前的应用程序可能存在一些问题,所以我决定在 4.0 中制作一个新的示例应用程序,但同样的问题。
namespace WindowsFormsApplication1
{
public partial class Form1 : Form`
{
public Form1()
{
InitializeComponent();
}
private void populate()
{
List<BillInfoCustom> oSalesList = new List<BillInfoCustom>();
BillInfoCustom oSalesType = new BillInfoCustom() { BillId = 1, BillDate = DateTime.Now.ToLongDateString(), CashPayment = 10, CreditCardPaymet = 20, CustomerName = "asda", TotalPrice = 20.0 };
BillInfoCustom oSalesType2 = new BillInfoCustom() { BillId = 1, BillDate = DateTime.Now.ToLongDateString(), CashPayment = 10, CreditCardPaymet = 20, CustomerName = "asda", TotalPrice = 20.0 };
BillInfoCustom oSalesType3 = new BillInfoCustom() { BillId = 1, BillDate = DateTime.Now.ToLongDateString(), CashPayment = 10, CreditCardPaymet = 20, CustomerName = "asda", TotalPrice = 20.0 };
oSalesList.Add(oSalesType);
oSalesList.Add(oSalesType2);
oSalesList.Add(oSalesType3);
dataGridView1.DataSource = oSalesList;
}
private void button1_Click(object sender, EventArgs e)
{
populate();
}
}
public class BillInfoCustom
{
public int BillId;
public double TotalPrice;
public double CashPayment;
public double CreditCardPaymet;
public string CustomerName;
public string BillDate;
}
}
这是我按下按钮后的输出: