我在winform项目中只用了 datagirdview控件,而且是强类型的数据表,现在我有两张 和别的表毫无关系的数据表,怎么才能嵌套的现实出来。比如: 每行的前头有个 + 号 ,点击加号 展开新表,显示相对应的数据。还有种方法就是,拆分最后的那个单元格,在一个单元格内显示多行多列的数据。该如何做??注:其实就是 收据编号 有很多条数据,想把它对应每笔交易,一条一条的 显示出来,不是现在我这样的一个单元格内显示出来。public partial class ShowSoldForm : Form
{
public ShowSoldForm()
{
InitializeComponent(); MainDataSet mds = new MainDataSet(); MainDataSetTableAdapters.TItemStockHistoryTableAdapter historyDA = new BIMS.MainDataSetTableAdapters.TItemStockHistoryTableAdapter();
historyDA.Fill(mds.TItemStockHistory);
MainDataSetTableAdapters.TOrderPrintoutTableAdapter pirntDA = new BIMS.MainDataSetTableAdapters.TOrderPrintoutTableAdapter();
pirntDA.Fill(mds.TOrderPrintout);
MainDataSetTableAdapters.TItemTableAdapter itemDA = new BIMS.MainDataSetTableAdapters.TItemTableAdapter();
itemDA.Fill(mds.TItem);
MainDataSetTableAdapters.ShowSoldTableAdapter ssda = new BIMS.MainDataSetTableAdapters.ShowSoldTableAdapter();
ssda.Fill(mds.ShowSold);
//MainDataSetTableAdapters.ShowBarcodeTableAdapter showbarcodeDA = new BIMS.MainDataSetTableAdapters.ShowBarcodeTableAdapter();
//showbarcodeDA.Fill(mds.ShowBarcode); MainDataSet.TItemStockHistoryRow[] historyRow = (MainDataSet.TItemStockHistoryRow[])mds.TItemStockHistory.Select("historytype=5");
MainDataSet.ShowSoldRow[] showRow = (MainDataSet.ShowSoldRow[])mds.ShowSold.Select();
for (int i = 0; i < showRow.Length; i++)
{
string str = "";
for (int j = 0; j < historyRow.Length; j++)
{
if (historyRow[j].itemid == showRow[i].itemid)
{
MainDataSet.TOrderPrintoutRow[] printRows = (MainDataSet.TOrderPrintoutRow[])mds.TOrderPrintout.Select("orderid='" + historyRow[j].orderid + "'"); for (int k = 0; k < printRows.Length; k++)
{
//string dd;
//dd = printRows[k].creadate.ToString("yyyy-MM-dd"); if (showRow[i].soldtime.Equals(printRows[k].creadate.ToString("yyyy-MM-dd")))
{
str += printRows[k].barcode.ToString() + " " + historyRow[j].quantity * (-1) + " ";
showRow[i].barcodes = str; }
}
}
}
} this.gdvShowSoldTest.DataSource = mds.ShowSold; this.gdvShowSoldTest.ReadOnly = true;
this.gdvShowSoldTest.Columns[0].HeaderText = "商品ID";
this.gdvShowSoldTest.Columns[1].HeaderText = "商品編號";
this.gdvShowSoldTest.Columns[2].HeaderText = "商品名稱";
this.gdvShowSoldTest.Columns[3].HeaderText = "售出數量";
this.gdvShowSoldTest.Columns[4].HeaderText = "售出日期";
this.gdvShowSoldTest.Columns[5].HeaderText = "收據編號";
}}
{
public ShowSoldForm()
{
InitializeComponent(); MainDataSet mds = new MainDataSet(); MainDataSetTableAdapters.TItemStockHistoryTableAdapter historyDA = new BIMS.MainDataSetTableAdapters.TItemStockHistoryTableAdapter();
historyDA.Fill(mds.TItemStockHistory);
MainDataSetTableAdapters.TOrderPrintoutTableAdapter pirntDA = new BIMS.MainDataSetTableAdapters.TOrderPrintoutTableAdapter();
pirntDA.Fill(mds.TOrderPrintout);
MainDataSetTableAdapters.TItemTableAdapter itemDA = new BIMS.MainDataSetTableAdapters.TItemTableAdapter();
itemDA.Fill(mds.TItem);
MainDataSetTableAdapters.ShowSoldTableAdapter ssda = new BIMS.MainDataSetTableAdapters.ShowSoldTableAdapter();
ssda.Fill(mds.ShowSold);
//MainDataSetTableAdapters.ShowBarcodeTableAdapter showbarcodeDA = new BIMS.MainDataSetTableAdapters.ShowBarcodeTableAdapter();
//showbarcodeDA.Fill(mds.ShowBarcode); MainDataSet.TItemStockHistoryRow[] historyRow = (MainDataSet.TItemStockHistoryRow[])mds.TItemStockHistory.Select("historytype=5");
MainDataSet.ShowSoldRow[] showRow = (MainDataSet.ShowSoldRow[])mds.ShowSold.Select();
for (int i = 0; i < showRow.Length; i++)
{
string str = "";
for (int j = 0; j < historyRow.Length; j++)
{
if (historyRow[j].itemid == showRow[i].itemid)
{
MainDataSet.TOrderPrintoutRow[] printRows = (MainDataSet.TOrderPrintoutRow[])mds.TOrderPrintout.Select("orderid='" + historyRow[j].orderid + "'"); for (int k = 0; k < printRows.Length; k++)
{
//string dd;
//dd = printRows[k].creadate.ToString("yyyy-MM-dd"); if (showRow[i].soldtime.Equals(printRows[k].creadate.ToString("yyyy-MM-dd")))
{
str += printRows[k].barcode.ToString() + " " + historyRow[j].quantity * (-1) + " ";
showRow[i].barcodes = str; }
}
}
}
} this.gdvShowSoldTest.DataSource = mds.ShowSold; this.gdvShowSoldTest.ReadOnly = true;
this.gdvShowSoldTest.Columns[0].HeaderText = "商品ID";
this.gdvShowSoldTest.Columns[1].HeaderText = "商品編號";
this.gdvShowSoldTest.Columns[2].HeaderText = "商品名稱";
this.gdvShowSoldTest.Columns[3].HeaderText = "售出數量";
this.gdvShowSoldTest.Columns[4].HeaderText = "售出日期";
this.gdvShowSoldTest.Columns[5].HeaderText = "收據編號";
}}
点击一行,然后取得想要的值,弹出新窗口,根据取得的值查到数据,在新窗口里面的datagridview显示出来
VS自带控件不好实现些功能,如坚持要这种效果建议用第三方的GridView很好用的,安装完后有Demo的,一看就懂。