我想在第二列中使用組合框創建數據組視圖。在第二列中使用組合框創建datagridview
目前我的datagrid綁定到數據表。現場患者是我需要的組合框。
下面的代碼添加了該字段,但它位於網格的末端並且被重複...即有2個病人字段。
DataTable dt = new DataTable();
DataColumn dtColumn;
dtColumn = new DataColumn("ClmDate", typeof(String));
dt.Columns.Add(dtColumn);
dtColumn = new DataColumn("Patient", typeof(Decimal));
dt.Columns.Add(dtColumn);
dtColumn = new DataColumn("ClmAmt", typeof(Decimal));
dt.Columns.Add(dtColumn);
cService cservice = new cService();
var trans = cservice.ClmView(txtNo.Text.Trim());
if (trans != null)
{
// Add items to datatable
foreach (var t in trans)
{
//save to datatable
DataRow row = dt.NewRow();
row["clmdate"] = t.clmdate.ToShortDateString();
row["patient"] = t.patient;
row["clmAmt"] = t.clmamt;
dt.Rows.Add(row);
}
}
Grid_Refresh();
private void Grid_Refresh()
{
grdTrans.DataSource = dt;
DataGridViewComboBoxColumn cb = new DataGridViewComboBoxColumn();
cb.HeaderText = "Patient";
cb.Name = "Patient";
cb.Items.Add("Foo");
cb.Items.Add("Bar");
grdTrans.Columns.Add(cb);
}
下面將網格我試圖重現的圖像...
http://s13.postimage.org/aale668uf/grd.png
任何幫助表示讚賞。
所以它不工作? – GameAlchemist 2012-07-18 23:12:19
並不是說它會影響問題,但是將日期存儲爲字符串有一個公平的可能性,在某些時候咬你。 「dtColumn = new DataColumn(」ClmDate「,typeof(String));」 – 2012-07-19 14:05:00
將有一個看看。只是給了一小部分代碼。網格比這個更大,幷包含一個按鈕。 – Rob 2012-07-27 04:03:18