提问人:Kahn Kah 提问时间:7/11/2017 更新时间:7/11/2017 访问量:59
列被称为 null,而实际上它们不是 C# WinForms
Columns are said to be null while they really aren't C# WinForms
问:
我创建了一个具有嵌套关系的 datagridview,该关系每行列出事件及其活动。这是通过使用 DevExpress 实现的:
我的问题是,我根本没有访问这些列的权限。
这意味着我无法设置隐藏的列、列宽等。NullReferenceException
这是我使用的代码:
private void DisplayData()
{
conn = new SqlConnection("Server=.\\SQLEXPRESS;Database=Ticketing;Integrated Security=true");
daIncidents = new SqlDataAdapter("Select * from incidents", conn);
daActivities = new SqlDataAdapter("Select * from Activity", conn);
ds = new DataSet();
daIncidents.Fill(ds, "Incidents");
daActivities.Fill(ds, "Activities");
DataColumn keyColumn = ds.Tables["Incidents"].Columns["IncidentID"];
DataColumn foreignKeyColumn = ds.Tables["Activities"].Columns["IncidentID"];
ds.Relations.Add("IncidentsActivities", keyColumn, foreignKeyColumn);
gridControl.DataSource = ds.Tables["Incidents"];
gridControl.ForceInitialize();
GridView gridView = new GridView(gridControl);
gridControl.LevelTree.Nodes.Add("IncidentsActivities", gridView);
gridView.ViewCaption = "Activities";
//gridView.Columns["ActivityID"].ReadOnly = true;
//gridView.Columns["Description"].Width = 40;
}
如果列真的不是,为什么说它们为 null?我尝试使用作为索引,但同样的问题。int
答:
2赞
mjwills
7/11/2017
#1
改变:
gridView.ViewCaption = "Activities";
自:
gridView.ViewCaption = "Activities";
gridView.PopulateColumns();
评论
0赞
Kahn Kah
7/11/2017
同样的问题:/
评论
}
?gridView.Columns
Immediate
Columns.Count()