[英]Populate a ComboBox present inside a DataGridView in windows Application using c#
我正在嘗試從數據庫填充DGV內部存在的組合框,但無法正常工作。 我的代碼是:-
private void popParent()
{
DataSet ds = new DataSet();
string sqlPS = @"SELECT * FROM tbl_acc_ledgergroup_msb";
try
{
using (FbConnection conPS = new FbConnection(connectionString))
{
conPS.Open();
using (FbCommand cmdPS = new FbCommand(sqlPS, conPS))
{
using (FbDataAdapter da = new FbDataAdapter())
{
da.SelectCommand = cmdPS;
da.Fill(ds);
DataGridViewComboBoxColumn cell0=(DataGridViewComboBoxColumn)(dataGridView1.Columns["Fee Head"]);
cell0.DataSource = ds.Tables[0].Columns[0].Table.DefaultView;
cell0.ValueMember = "lg_id";
cell0.DisplayMember = "lg_name";
}
}
}
}
catch (FbException ex)
{
MessageBox.Show("PP-->>" + ex.Message);
}
}
目前,程序退出而沒有從該行給出任何錯誤消息
cell0.DataSource = ds.Tables[0].Columns[0].Table.DefaultView;
請告知我的代碼可能有什么問題。 提前致謝。
變化:
cell0.DataSource = ds.Tables[0].Columns[0].Table.DefaultView;
至
cell0.DataSource = ds.Tables[0];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.