Home
Options

Dump to DataGrids - Hyperlinqs that resolve to null

When dumping results to Data Grids, rather than Rich Text, it renders "complex"* objects as Hyperlinqs (because Data Grids only show nesting one level deep), which resolve themselves into a new output panel when you click on them. This is all well and good.
*Not sure on the technical term, sorry

Interestingly, I have noticed that:
  1. If all the values in the column are of the same type, then each cell contains a Hyperlinq, rendered with the name of the column. However, quite often the value in the cell is null, and I find it annoying/tedious to click on the Hyperlinq just to see that this is the case.
  2. Otherwise (when not all of the values in the column are of the same type), null values appear as null, and non-null values are displayed as Hyperlinqs containing the name of the type of the value in the cell.
Basically, I was wondering, is there a way to get the data grid to always show nulls as null and only show Hyperlinqs for non-null objects, even when the column only contains one type? Personally I'm not too bothered about whether the Hyperlinq displays the name of the column of the type of the value in the cell, but basically I want it to be clearer from a glance which values are null and which aren't.

To explain what I mean in examples, the following (C# statements) code shows this behavior:

var rand = new Random();
// 1: shows a column full of "b"s that may or may not resolve to null when you click on each one - because they are all the same non-value type. Ideally, it would either show null or a Hyperlinq.
Enumerable.Range(1, 15).Select (e => new { a = "a", b = rand.Next(0, 2) == 0 ? null : new { d = 5 - e }, c = e }).Dump();
// shows null where applicable, because value type
//Enumerable.Range(1, 15).Select (e => new { a = "a", b = rand.Next(0, 2) == 0 ? null : (int?)e, c = e }).Dump();
// 2: the following is the behavior I would like to see when all values in the column are the same type:
Func ex = i => i == 0 ? null : i == 1 ? (object)new { d = "example" } : (object)EventArgs.Empty;
Enumerable.Range(1, 15).Select (e => new { a = "a", b = ex(rand.Next(0, 3)), c = e }).Dump();
Mostly I use output in rich text to get around this "problem", but there are times when I find data grids preferable. I wonder if anyone else feels the same? :)

Thanks for your time reading this ;)

Comments

  • Options
    I have just noticed that the forum has eaten part of my example query - the "Func" on the 2nd to last line should be:
    Func<int, object>
  • Options
    In order to know whether an object is null, LINQPad has to query the property. The difficulty is that if the data is from LINQ to SQL or EF and the property is a lazily loaded entity, this will cause a round-trip back to the database. This will cause a potentially big performance hit, without it being obvious to the user what's going on.

    A workaround is that you can right-click the column and click 'Expand hyperlinks in this column' to explicitly expand hyperlinks.
  • Options
    ah good point, thanks for the useful tip Joe :)
Sign In or Register to comment.