我正在尝试使用3级Master Detail View创建gridview。
我的观点应该包含:
我使用以下代码:
public partial class Manage_Other_Company_Invoices : DevExpress.XtraBars.Ribbon.RibbonForm
{
private int companyID;
DataAccess_CompanyInvoice dal = new DataAccess_CompanyInvoice();
DataSet dataSet;
public Manage_Other_Company_Invoices(int companyID)
{
this.companyID = companyID;
DisplayData();
}
private DataSet GetItems()
{
dataSet = new DataSet();
dataSet.Clear();
dataSet.Tables.Add(dal.CreateInvoiceTable(companyID));
dataSet.Tables.Add(dal.CreateInvoiceLinesTable());
dataSet.Tables.Add(dal.CreateInvoiceLineDetailsTable());
DataColumn keyColumn1 = dataSet.Tables["Invoice"].Columns["invoiceID"];
DataColumn foreignKeyColumn1 = dataSet.Tables["InvoiceLines"].Columns["invoiceID"];
dataSet.Relations.Add("Invoice", keyColumn1, foreignKeyColumn1, false);
DataColumn keyColumn2 = dataSet.Tables["InvoiceLines"].Columns["company_Invoice_Line_ID"];
DataColumn foreignKeyColumn2 = dataSet.Tables["InvoiceLineDetails"].Columns["InvoiceLineID"];
dataSet.Relations.Add("InvoiceLineInvoiceLineDetails", keyColumn2, foreignKeyColumn2,false);
return dataSet;
}
private void DisplayData()
{
//MessageBox.Show("test" + GetItems().Tables["Invoice"].Rows.Count.ToString());
gridControl.DataSource = GetItems().Tables["Invoice"];
gridControl.ForceInitialize();
}
}
问题在于,当我在DisplayData()
函数中取消评论时,它显示该表中的正确行数。但奇怪的是,是在抛出空引用异常之后的行。
我做错了什么?