I have a grid in which I add products (Screen shot attached). I want to calculate some values based on values in some cells. Here is my scenerio
When the value in Qty cell is changed I want to calculate the value of Amount column (Amount = Qty * Unit price)
The first element in my Unit combobox column should be selected by default when a new row is added but that is not the case, I have to manually select the item as shown in row2 of screen shot.
I can't seem to find the RowAdded event or something similar which I am so used to of using in ASP.Net controls.
I know that if I add the textboxcolumn from code behind then I can handle its textchange event, but I have added column through “Property Builder” and can’t seem to find the controls from the row.
Note: I am using Q2 2010 SP2
Can anyone please help me.
5 Answers, 1 is accepted
there are several ways thart you could make your calculations depending on what it is you wish to do. (sorry, the screenshot sisn't seem to be there on your post).
Please could you let me know a bit more about what you want to do. My first guess is that you wish to have a calculated column to calculate some other columns. If that's the case, then you might wish to have a look at this help topic on calculated columns.
You can also calculate at the start of end of a row using a summary row
If neither of these is what you're looking for, or if you need more information, then please let me know
Thanks for your reply. Sorry due to some reason the Screen Shot didn't get attached with the last post. I have attached it now. Actually what i would ideally want is to get reference of the text box control in the TextBoxColumn cells and the Drop down control in the DropDownListCell. Then I can write code agains there Text changed event and Selected Index changed event.
Here is my scenerio in detail.
My grid is not bound to a datasource instead I am manually adding products and there prices in it based on the user selection.
I would like the user to only enter numeric values in Qty column and Decimal values in Disp Price & Disc % columns.
Secondly whenever user changes value in Qty column the amount column should be updated accordingly.
Finally the first unit in Units column (i.e Kg(s)) should be selected by default, which is not the case.
I am really struck here at these points and would really appretiate your help.
Syed Afraz Ali
I figured out how to allow only numeric values. I added MaskedTextBoxColumn and set its Masked property to "f". This seems to work perfectly. The other questions are still open.
Please take a look at the following example:
I believe it incorporates everything you need
Hope this helps, if you have any other questions or comments, please let me know,
Telerik WinForms MVP
Thanks for your reply. Your post and this post solved my problem perfectly. It turned out, my logic for calculating amount is a bit complex and a simple expression would not have worked for me. So I used the approach mentioned in this post.