DataGrid
コントロールのTableStyles
コレクションが指定された時点で空であり、DataGridTableStyle
コレクションが追加されるまで、そのままになっています。
プロパティの正しい値を設定するための提案を使用して、DataGrid
に必要なパブリックフィールドのみを含む新しいDataGridTableStyle
オブジェクトを作成して追加して、目的の結果を達成しました。
// Create a DataGridTableStyle to hold all the columns to be displayed in the DataGrid
DataGridTableStyle myTableStyle = new DataGridTableStyle();
myTableStyle.MappingName = myBindingSource.GetListName(null); // This is the magic line
myTableStyle.GridColumnStyles.Clear();
// Add some DataGridColumnStyles
DataGridTextBoxColumn columnRowId = new DataGridTextBoxColumn();
columnRowId.MappingName = "idx"; //This must match the name of the public property
ColumnRowId.HeaderText = "Record";
tableStyleReportsSummary.GridColumnStyles.Add(columnRowId);
// Add the table style to the DataGrid
myDataGrid.TableStyles.Clear();
myDataGrid.TableStyles.Add(myTableStyle);
これはDataGridViewコントロール用ですか? – jp2code
いいえ、.NET CF 3.5 DataGrid。 –