Category Archives: Geek

SelectionChangedEvent in RadGridView

If you have used RadGridView with a GridViewComboBoxColumn, you know it does not support SelectionChangedEvent directly. There are many scenarios where you want to handle some validation or perform some action when the user selects an item in a combo box but the absense of SelectionChangedEvent for GridViewComboBoxColumn makes this really hard. Good news is, there is a solution. Here it is, see if it helps.

Let’s say you have a RadGridView defined like this:

<telerik:RadGridView x:Name="myGridView">
 <telerik:GridViewComboBoxColumn Header="Page" UniqueName="column1"  />

In your code behind, preferably in the Loaded event, add this code:

new Telerik.Windows.Controls.SelectionChangedEventHandler(ComboBox_SelectionChanged));

Add an event for Selection changed event. The name of your method and the event above should match.

 void ComboBox_SelectionChanged(object sender, RadRoutedEventArgs args)
RadComboBox comboBox = (RadComboBox)args.OriginalSource;

if (comboBox.SelectedValue == null)

// Get the current cell
GridViewCell cell = myGridView.CurrentCell;

// Handle the situation where a cell is null. It can be when you are adding a new row
if (cell == null)

GridViewRowItem row = cell.ParentRow;
GridViewColumn col = cell.Column;

// This if block here is to handle only the combo box column desired. You can
// have multiple combobox columns and this event will be triggered for all of them.
// Handle what is required and ignore the rest
if (col.UniqueName != "column1") // Unique name that you specified in the XAML

// YourDataObject is whatever data object you are using
YourDataObject item = comboBox.DataContext as YourDataObject;

//SelectedItem returns object. Convert it to whatever your binding object type is
object selectedItem = comboBox.SelectedItem;

// Now that you have your selected item, you can do whatever you want.
// In case you want to disable other cells on this row, just use row.Cells property.

That’s it. You are all set now.

Some points to note:
1. SelectionChanged event will be triggered for all combo box columns and combo boxes you have. You need to find out if the deisred combo box column is changed.
2. This event is triggered not only after the selection is changed, but also when the user just clicks on the combo box. There is a solution to handle this, but that’s another story altogether.
3. This was tried with VS 2010 and Silverlight 4.

Virtual PC: Switching between virtual pc and host pc

Once you start using your virtual PC, how do you get control back to the host PC? The help document of VPC says to press the host key, but what on earth is the host key? It’s the right ALT key of your keyboard. Not any ALT key, but the RIGHT ALT key. Press it and the mouse control comes back to your host PC.

You can launch your virtual PC in full screen mode. Once you have done that, how do you quit full screen mode? Again, press host key and enter. That is RIGHT ALT + Enter.

Simple, yet it took me some time to figure it out.

Regular expression for a line with only white spaces

I had this requirement to check whether the input string contains only white spaces. I am not a regular RegEx user, so it took me some time to achieve this.

^[ \t\r\n]*$

That’s it. The meaning of the above pattern is [Beginning of line] [0 or multiple white spaces] [End of line]. Note that this pattern matches an empty string also, since we have given * after white spaces. If you want to strictly look for white spaces and exclude empty strings, then change the * to +.

This is not such a big deal that it requires a blog post of its own, but I didn’t find this information when I looked for it. So putting this out there for anyone who comes looking for it.

Review: Introduction to Silverlight 3 by Laurence Moroney

The book intends to give an overview of the features in Silverlight 3. It starts with very basic things like creating a Hello world project in Silverlight 3, the different elements in SL3 project and hand coding all those elements outside the Visual Studio environment. Later on, the book dives into advanced-beginner topics like writing XAML code, using Expression Blend etc.

The book touches on different topics at a superficial level and doesn’t give deep insight into any of the topics. This is what is expected from an ‘Introduction’ book, so the purpose is served. There is a detailed section (couple of chapters) on UI controls available in SL3. It introduces basic controls like Button, Text Block, Label and moves on to slightly advanced controls like DataGrid, ScrollViewer etc. The author explains designing UI using XAML. This is a must for anyone who don’t have Blend. Learning XAML is the biggest challenge in XAML, in my opinion.

There is a small section on MVVM where the author discusses two-way data binding. I was hoping this section would be a bit deeper, but I guess that was not in the scope of this book.

The intention of the book is not to showcase the differences in SL3 and the previous versions of Silverlight. It isolates SL3 and focuses only on this version. For someone who is starting to learn Silvelright and chooses SL3 as the version, then this book is ideal to start with. The reader need not worry about the compatibility issues with older versions unnecessarily.

If you are looking for a quick familiarity to Silverlight 3, then this is the book for you.

Tagged , , ,

Firefox 3.5: Firefox exits when you close the tab

There is a serious problem with Firefox 3.5. When you have only one tab open in Firefox and when you close that tab, instead of opening a new, blank tab, Firefox itself exits. This is annoying because you would expect a new tab to open, but you see Firefox disappear in front of you and your heart sinks.

Turns out there is an easy fix for this.

1. Open Firefox and type about:config in the browser address bar. You will get a warning, acknowledge it and carry on.

2. In the filter, type browser.tabs, you will see some entries in the table. You will also see ‘browser.tabs.closeWindowWithLastTab’.  Its value should be true. Right click on this and click on Toggle. The value should change to false.

3. Close the browser and open again.

4. Verify that the browser doesn’t close when you close the only open tab.


Tagged ,

Visual Studio: Restore Missing Templates

Symptom: You cannot add a new project or an item in Visual Stuio IDE.

Problem: Open the Event Viewer (Control Panel->Administrative Tools->Event Viewer) and see if the suggestion says “Run devenv.exe /installvstemplates”. If this is the case, then the problem is the template files are missing.


1. Close all instances of Microsoft Visual Studio.

2. There are two folders under IDE folder (C:\Program Files\Microsoft Visual Studio xx\Common7\IDE), namely ProjectsTemplateCache and ItemsTemplateCache. Delete these two folders. Yes, I said, delete. If you are hesitant, don’t worry, it will go to the recycle bin from where you can retrieve them.

3. After deleting the folders, open the command prompt and run this command: Devenv /InstallVSTemplates .

4. Done. The template files should be restored and you should be able to add new projects and items.

I found myself in this situation out of nowhere. I was innocently coding and debugging and when I tried adding a control to my project, I suddenly see this error message. Thank God, the solution was this simple. Imagine spending another 4 hours on reinstalling Visual Studio. I wonder why I got into this situation, in the first place. Any idea?

Tagged , ,

Mindtree Osmosis 2007: An external view



Last weekend, I attended Mindtree’s annual tech fest, Osmosis. This year they had organized the fest in the unconference style. To quote from their site

“To foster greater participation and to cut through the air of formality, Osmosis 2007 has adopted the “unconference” mode. Unconference merges the distinction between the speaker and the audience, and everyone is a participant.”

Also, this year they opened the doors for external participants, which is why I could attend it. My brother invited me over and we both had a lot of fun, to say the least.

The day began with a talk by Ashok Soota, Chairman of Mindtree. This talk itself was in unconference style. Soota spoke for a few minutes and left the ground open for participants to ask him questions. After the short and sweet talk, unconference sessions began.

The first session I attended had a rather controversial title ‘Are software engineers getting extinct?‘ With great minds like Bagchi, Soota, KK, Partha, Kamran, Desmukh in the room, speakers had a tough time controlling the audience. The argument was basically that the magic of software industry is fading, and with automation being the talk of the town, software might become extinct. The session saw some good participation from the audience.

Twitter session caught my attention next. This session was like an introduction to twitter and micro-blogging. It was not very useful for me because I knew about twitter beforehand. This was more like one-way information flow, there was not much to argue or discuss, so no heated debate here.

I and my Project Manager was the next session which me and my brother wanted to attend. But by the time we reached the room, it was so jam packed, we didn’t have place even to stand. We got to rest our minds for half an hour before breaking for lunch. There was live music by MAG, Mindtree’s very own musical band and they belted out some good numbers.

Post lunch, it was the much awaited session on Google’s Android. It was meant to be an introductory session on Google’s mobile OS and SDK, but the session veered to the debate mode when one person decided to argue about every point the speakers made. The speakers were not prepared for this and it was clearly evident. Some good points made by Mindtree minds about why we need Android at all and why open source is scary!

Another controversial topic – Innovation. After being fed up of the ‘compulsary innovation’ at my organization, I was hoping this session will help in venting out the frustration. Sigh, it only added to it. I saw the same attitude in Mindtree too. People who belong to the innovation team are all ga-ga over it and always inspiring (read as forcing) people to think out of the box and innovate, whereas the rest of the world is fed up of it and cringe whenever they hear the word innovation. We had some good argument about what is an idea, an innovation and an invention.

This was followed by the grilling session of CTOs Vinod Desmukh, CTO of R&D Services and Kamran Ozair, CTO of IT Services. The two minds were bombarded with questions collected previously from Mindtree minds. There were some interesting questions and both of them handled it really well. This session gave a glimpse of how strong both of them are in their respective domains. I was floored.

Mr. Bagchi took over next and gave a totally different speech. The Bagchi on stage was completely different from what I had imagined him to be. The T-shirt clad bald man on stage cracking jokes on his colleagues and sometimes being not so politically right was different from the man who I had seen through his columns in TOI. With this the unconference session came to an end.

This was the first time I attended a fest in this format and honestly, I didn’t know what to expect. The moment I stepped into the conference hall, I knew I was going to like it. The atmosphere was electric and the attitude, contagious. When so many great minds (read as nerds) come together and discuss their passion, how can it be not good? It was a pity to see some girls touching and re-touching their make-ups in rest rooms when such serious debate was going behind closed doors. Apparently some people turned up to have fun in a different way.

The whole thing was organized very well. Every session started on time and ended on time – it is mind boggling to even imagine how this was achieved. Facilities like lunch, coffee, tea, handouts, badges – everything was in its place. As an external participant, I was awed! And I was told the whole credit goes to Shahnawaz Khan. Special thanks to him – he does make it look so easy. The standing ovation he got at the end of the day just goes on to say how much hard work and effort he had put in.

As an external participant, I am in awe of Mindtree. To try something like this and to let outsiders attend, takes a lot of guts. Mindtree took the plunge and came out victorious. I enjoyed every moment of it and this weekend was one of the very few weekends which I consider well spent. Now that the unconference is over, I wish it comes around soon. I can’t wait to attend Osmosis 2008.

Tagged , ,


Two CPUs. Two monitors. One mouse. One keyboard. The equation doesn’t sound feasible? Synergy makes it feasible.

Synergy is an open source tool, implemented in C++ which lets you share a mouse and a keyboard between multiple computers. The application is small and considering that it works over TCP/IP, it is really fast.

Setting up Synergy is very easy. Install Synergy on all machines you want access to. Assign one machine as server and the others as client. What is the difference? The mouse and keyboard which is assigned as server shares the peripherals between all machines whereas the peripherals belonging to the clients are just theirs – there is no sharing.

Matt Cutts introduced me to this nifty tool and now that I have used it for a week, I am wondering how I ever survived without it. Matt gives a good step-by-step description of setting up Synergy. Go over to his blog or see the help page on Synergy Sourceforge. Install it and liberate yourself from managing multiple mouses and keyboards.

Article on Multi-threading in C#.NET

For anybody who wants to gain some basic and intermediate knowledge on multithreading in C#.NET, John Skeet’s article is a must read.

The article displays the in-depth knowledge of the author on this topic. The author has painstakingly listed down the different synchronization objects available in C#. He also lists the pitfalls that one might get into while programming using threads. That explains why the article is so lengthy.

This article has everything one needs to know about multi-threading in the .NET environment. Bookmark it, you know you will need it one day.

Type.GetType and referred assemblies

Problem Statement:

There is a DLL called CommonAssembly. This contains a namespace called CommonNamespace. This namespace contains a class called CommonClass.

Another project adds a reference to CommonAssembly and wants to get the type of CommonClass using the method Type.GetType.

Additional Information:

// This statement won’t work.

// This will not work either

Since CommonClass type is defined in a referred assembly, Type.GetType will not be able to get the required type.


Type.GetType(“CommonNamespace.CommonClass, CommonAssembly”);

Anything that is given after the comma (“,”) is taken as the assembly name. This assembly is searched for the given type name.

If the required class is not encapsulated in any namespace, then omit the namespace name.

Type.GetType(“CommonClass, CommonAssembly”);

If this doesn’t work, then try giving the fully qualified name of the assembly.