私は、一部のカラムが[Browsable(false)]
とマークされたクラスにバインドするデータグリッドを持っています。これらの列は空白になります。これをオフにする方法はありますか?[Browsable(false)]カラムにdatagridviewをバインドします
私は自動バインドを使用せず、自分自身で列を作成し、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;
}
}
いくつかのコードは、列コード... –