我的datatable
有很多列,
现在我有datagridview
已经使用这些代码设计的列:
frm.RationFeedsdataGridView.ColumnCount = 4;
frm.RationFeedsdataGridView.Columns[1].HeaderText = "Number";
frm.RationFeedsdataGridView.Columns[1].HeaderText = "Name";
frm.RationFeedsdataGridView.Columns[2].HeaderText = "Quantity";
frm.RationFeedsdataGridView.Columns[3].HeaderText = "Percent";
现在我想将datatable
的特定列绑定到datagridview
frm.RationFeedsdataGridView.Columns["Name"].DataPropertyName = "FeedName";
FeedName是datatable
我该怎么办?
答案 0 :(得分:1)
这就是我解决问题的方法:
frm.RationFeedsdataGridView.AutoGenerateColumns = false;
frm.RationFeedsdataGridView.Columns[1].Name = "Name";
frm.RationFeedsdataGridView.Columns[1].HeaderText = "Name";
frm.RationFeedsdataGridView.Columns[1].DataPropertyName = "FeedName";
frm.RationFeedsdataGridView.Columns[2].Name = "Quantity";
frm.RationFeedsdataGridView.Columns[2].HeaderText = "Quantity";
frm.RationFeedsdataGridView.Columns[2].DataPropertyName = "Quantity";
frm.RationFeedsdataGridView.Columns[3].Name = "Percent";
frm.RationFeedsdataGridView.Columns[3].HeaderText = "Percent";
frm.RationFeedsdataGridView.Columns[3].DataPropertyName = "Percent";
frm.RationFeedsdataGridView.DataSource = DTable;