After a short hiatus, I am back again into this corporate world. So, it’s hello to the world all over again.
As I play with some new tools, expect some posts on WCF, WPF and Silverlight in the coming days. Watch this space.
Let’s talk about coding and lots more…
If you have ever used a DataGridView with a DataGridViewComboBox column, then you would have definitely noticed that you need multiple clicks to select an item in the combo box. This is very annoying because every time you want to select a different item from the combo box, you need at least 2-3 clicks.
Fix
Fortunately, there is a simple fix for this: set the EditMode property of the data grid view to EditOnEnter. So, when the user enters the control, the cell is automatically put in edit mode, so when you actually click on the combo box, you can see the drop down list.
A bug
That being said, there is a bug associated with this. With the EditMode property set to EditOnEnter, when you select a row by clicking on the row header, the entire row is selected, but one cell will be in edit mode. What this means is if you try to delete the row by selecting the row header, you cannot delete the row because the delete key is actually being sent to the cell being edited and not the row.
This page has more details on this bug and also a workaround.

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.
This seems to be a straight forward thing, but Microsoft only knows why this simple feature is not supported in DataGridView.
If you have a ComboBoxColumn in your DataGridView and you want to know what is the selected index of the combo box, then you need to do this:
1. Handle the EditingControlShowing event of DataGridView. In this event handler, check if the current column is of our interest. Then we create a temporary ComboBox object and get the selected index:
private void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 0)
{
// Check box column
ComboBox comboBox = e.Control as ComboBox;
comboBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
}
}
void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
int selectedIndex = ((ComboBox)sender).SelectedIndex;
MessageBox.Show("Selected Index = " + selectedIndex);
}
A rather round-about solution where a simple one would have sufficed.
Problem:
There is a TreeView control with n number of nodes. When the user right clicks on the TreeView control, get the node on which the right click was performed.
Background:
In TreeView control, SelectedNode property is set whenever left click occurs. This is not true for right clicks. So, we need to have some workaround for this.
Solution 1:
The most popular solution is to handle the MouseDown event. Check if the click was a right click and then use the TreeView control’s GetNodeAt API to get the node which was clicked at.
private void treeView1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
TreeNode selectedNode = treeView1.GetNodeAt(e.X, e.Y);
MessageBox.Show("You clicked on node: " + selectedNode.Text);
}
}
Solution 2:
Handle the NodeMouseClick event. The TreeNodeMouseClickEventArgs has the node which was clicked at.
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
MessageBox.Show("You clicked on node: " + e.Node.Text, "Solution 2");
}
}
SelectedNode property of a treeview is set whenever a left click occurs. Why can’t the same be applied for right click? Right click on a treeview is such a common UI event, that users will benefit from it.