1
我有一個datagrid,我綁定到類有一些列標記爲[Browsable(false)]
。這些列顯示空白。有什麼方法可以解決這個問題。綁定datagridview到[Browsable(false)]列
我沒有使用任何自動綁定,但自己創建列並設置DataPropertyName屬性。
我花了很長時間才發現爲什麼他們現在是空白我希望有一些簡單的方法來顯示它們中的值。我能想到的唯一的事情就是編寫我自己的DataGridViewColumn類並重新實現綁定。任何其他想法?
下面是一些代碼,演示了這個問題,GridBrowsableProblem是一個新的窗體,DataGridView放在它上面。當運行ProblemProperty沒有價值。
public partial class GridBrowsableProblem : Form
{
public class ProblemTestClass
{
[Browsable(false)]
public string ProblemProperty { get; set; }
public string AnotherProperty { get; set; }
}
public GridBrowsableProblem()
{
InitializeComponent();
DataGridViewTextBoxColumn column1 = new DataGridViewTextBoxColumn();
column1.DataPropertyName = "ProblemProperty";
DataGridViewTextBoxColumn column2 = new DataGridViewTextBoxColumn();
column2.DataPropertyName = "AnotherProperty";
ProblemTestClass item = new ProblemTestClass();
item.ProblemProperty = "test1";
item.AnotherProperty = "test2";
BindingList<ProblemTestClass> bindingList = new BindingList<ProblemTestClass>();
bindingList.Add(item);
dataGridView1.Columns.Add(column1);
dataGridView1.Columns.Add(column2);
dataGridView1.DataSource = bindingList;
}
}
一些代碼將幫助,列代碼... – 2012-02-23 07:29:49