Wednesday, October 30, 2013

XtraGrid : Use more specialized event for better code in handlers

DevExpress's XtraGrid is quite a complex beast. It's a library with tons of features and it can be overwhelming to use it optimally at first. So you might get your job done with certain way but overtime you find something new that you didn't notice at first that actually a better way than how you did previously.

That is the case when I just notice that XtraGrid has RowCellClick event that fires on specific cell click. I have been using Click event previously. Click event work just fine, however within it I need to have numbers of code to filter out cases that is not relevant to what I am trying to achieve. On the other hand, RowCellClick already comes with RowCellClickEventArgs with all the relevant info has been nicely parsed for use. The code get much cleaner when I adapt the code from handling Click event to RowCellClick.

So, the lesson is to use the most specific event that fit your case instead of the more general one. It can be a good guideline for using other parts of DevExpress library too. DevExpress components do a lot of inheritance from .Net components and with it inherit lots of pre-defined functions too. So, it has to do some specialization to extend the functions. Hence, it has some functions that is quite similar but slightly specialized.

No comments: