Saturday, July 28, 2018

c# - DataGridView displays empty cells when bound to typed DataTable

I'm creating a simple application that simply populates a DataGridView with a strongly typed DataTable. My problem is that all the cells show up empty despite containing data, I have a CellDoubleClick event which can pick up the underlying value of the cell (which is typed as expected) but the column is shown as empty.


Objects of type INode all have a ToString() method defined and my assumption was that the DataGridView would be intelligent enough to call that method any show that as the cell contents but it appears not.


Here is my current test code:


        //Add some fake test data
DataTable data = new DataTable();
data.Columns.Add("Subject");
data.Columns.Add("Predicate");
data.Columns.Add("Object");
data.Columns["Subject"].DataType = typeof(INode);
data.Columns["Predicate"].DataType = typeof(INode);
data.Columns["Object"].DataType = typeof(INode);
Graph g = new Graph();
DataRow row = data.NewRow();
row["Subject"] = g.CreateURINode(new Uri("http://example.org/subject"));
row["Predicate"] = g.CreateURINode(new Uri("http://example.org/predicate"));
row["Object"] = g.CreateURINode(new Uri("http://example.org/object"));
data.Rows.Add(row);
this.dvwBrowser.DataSource = data;
this.dvwBrowser.AutoResizeColumns();

How can I get the value of the ToString() method to be displayed in the cells when I bind the DataTable to the DataGridView?

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...