Monday, November 23, 2009

SelectedIndex if nothing selected

SelectedIndex property of Infragistics' WebCombo class has the following syntax


public int SelectedIndex {get; set;}

The documentation reads 'If no row is selected, this property returns Nothing or Null.' That sounds suspiciously since int cannot be null.

The property actually returns -1 if there are no selected rows.

By the way, the index is zero-based, i.e. the first row has the index 0.

Thursday, November 12, 2009

'+' not supported in datakey

Users reported us that sometimes the selection is lost in UltraWebGrid. We managed to discover that the problem occurs only when the key column contains '+'. The selection is recognized OK on client side, but on server side it behaves as if the selected row was the one without '+', i.e. none if there was no such row.

Having the data source


[DataObject]
public class DataProvider
{
[DataObjectMethod(DataObjectMethodType.Select)]
public static IEnumerable SelectData()
{
yield return new { Column1 = "a+b" };
yield return new { Column1 = "a b" };
}
}

and the grid

<igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" DataSourceID="ObjectDataSource1">
<Bands>
<igtbl:UltraGridBand DataKeyField="Column1">
<Columns>
<igtbl:UltraGridColumn Key="Column1" BaseColumnName="Column1" IsBound="True"></igtbl:UltraGridColumn>
</Columns>
</igtbl:UltraGridBand>
</Bands>
<DisplayLayout …>…</DisplayLayout>
</igtbl:UltraWebGrid>

you can select the row with "a+b", but once you enter server code (e.g. for server event handling), the selection is changed to "a b".

We needed to introduce another column to store the key value with '+' escaped somehow (e.g. replaced for another character).

Updated 3 February 2010:
I have been told by a colleague that even server events are not raised for a row having '+' in its key.

Thursday, September 3, 2009

Comma-separated Lists

One needs to convert a list of objects to comma-separated list of values sometimes. I often see StringBuilder used with some sort of loop. The most intellectual challenge is not to write comma after the last item; either there is some conditional expression in the loop step or some post processing is included to remove the last comma. Usually the result is consisting of several lines of code, perhaps too many for the purpose.

Users enthusiastic about Linq tend to involve Enumerable.Aggregate. Still String.Join may be the most straightforward method many times.

Thursday, July 30, 2009

The First Contact with FO.NET

I had a training recently on XSLT and XSL-FO. We were using java Apache FOP there. I was quite interested in the technology and was keen to give FO.NET a try.

Yesterday, I got to it finally. I found two drawbacks so far. Attribute width on inline element had no effect and I only found a workaround by using table. Then I discovered that block-container is not supported by FO.NET. But since you can have nested blocks, it is not a big issue.

I only worked with relatively simple document, so I guess there may be much more issues when using FO.NET. Still I was pleased with the output. I think FO.NET (and XSL-FO in general) might be a good option for creating PDF documents, especially when the source data are in XML.

Tuesday, July 21, 2009

Pair programming begins

I suggested a colleague to try pair programming and he agreed. After one week, we reviewed our first impressions.

First of all, I was interested in quality of the code we produce. However, it is difficult to say, what the quality is. We chose maintainability term instead. Zdenek (my pair) consider it significantly better in pair, I think it is somewhat better.

As for velocity of development, Zdenek finds it really faster, I find it somewhat faster. However, these are only our first impressions. I think we can explain much of velocity gain by ongoing focus. I mean, if you start losing concentration, your pair takes over so there are much less slow downs comparing to working alone.

I feel a little bit less of personal comfort, while Zdenek did not observe that.

I was also interested in the level of learning. Zdenek is extremely satisfied, because he is new to project and pairing helps him very much to get to it. I feel like learning less, but that is mostly becuase of different style of work now. Especially, I am the driver most of time, although it got better in last days.

We both expect the higher probability of success of the project.

There are some practical issues regarding pair programming. We have no specific keyboard sharing rules yet. Mostly, the one who feels bigger focus is a driver. We already changed a workplace a bit (moved a piece of furniture) to make us feel more comfortable at a single table.

Basically, our first impressions are mostly positive and we want to go on with pair programming. We extremely appreciate ongoing focus and ongoing code-reviewing.

Tuesday, April 21, 2009

Strange values in chart

Infragistics stacked column chart allows to display both negative and not negative values. However, I was adding some post processing based on values and discovered that one has to be careful with Box.Value.

Among others I had a stacked column with values 0, -50, 0, 50, 0. This is what I obtained (Box[][] rows were collected from SceneGraph by Row and Column):


((NumericDataPoint)rows[3][0].DataPoint)
Value: 0.0
((NumericDataPoint)rows[3][1].DataPoint)
Value: -50.0
((NumericDataPoint)rows[3][2].DataPoint)
Value: 0.0
((NumericDataPoint)rows[3][3].DataPoint)
Value: 50.0
((NumericDataPoint)rows[3][4].DataPoint)
Value: 0.0

rows[3][0].Value
0.0
rows[3][1].Value
-50.0
rows[3][2].Value
-50.0
rows[3][3].Value
50.0
rows[3][4].Value
-50.0


There is a kind of warning in the documentation of Box.Value:

The intent behind any data objects referenced by this property are dependent upon the Layer that added this Primitive to the scene graph.
They tend to use it, though, as I saw on forums.

I spent some time trying to find better way then casting Box.DataPoint to NumericDataPoint, but I failed.

Monday, April 6, 2009

Selecting not nulls?

Having a collection IEnumerable<Nullable<T>> myCollection you can select values that are not null by calling myCollection.OfType<T>(). What is not so obvious is that calling myCollection.OfType<Nullable<T>>() would provide the same result.

This is because Enumerable.OfType<TResult> uses is internally to determine the type of item. It means, you can use Enumerable.OfType<T>() even for reference type T to get items that are not null.

Of course, I would prefer calling Where<T>(item => (item != null)) to calling OfType<T>() because the first call is much better in revealing its intention.

Tuesday, January 6, 2009

Collection Initializers

Collection initializers are very welcome in C# 3.0. Typing

new List<int> { 1, 2, 3 }

is of course much more convenient then typing

List<int> l = new List<int>();
l.Add(1);
l.Add(2);
l.Add(3);


However, when seeing examples (e.g. MSDN), one could think that you are limited in a single type in a collection initializer. But that is not true. You can use several Add overloads arbitrarily. Having the class

class MyCollection : IEnumerable
{
public void Add(string s) { ... }
public void Add(int i) { ... }
public void Add(SomeClass c) { ... }

//...
}

you can initialize it like this

new MyCollection
{
"something",
1,
2,
new SomeClass { ... },
"yet another string",
3
}