Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13934 |

    I’m in the middle of evaluating the Grid control. So far I like what I see. I want to use the grid to make a small order form for the application I am writing. There is a Price column a Quantity column and a Total column. When someone updates the Quantity column, I’d like to take the value, multiply it by the price column and put the result in the Total column. Is this possible?

    Thanks in advance for all your help.

    Imported from legacy forums. Posted by twlichty (had 2311 views)

    User (Old forums)
    Member
    Post count: 23064

    Yes it is. Here’s an example of how to do this (untested code):<code>EventHandler handler = new EventHandler(CalculateTotal);
    myGrid.DataRowTemplate.Cells[“Price”].ValueChanged += handler;
    myGrid.DataRowTemplate.Cells[“Quantity”].ValueChanged += handler;
    private void CalculateTotal(object sender, EventArgs e) {
    Cell cell = sender as Cell;
    if (cell == null) return;
    CellRow row = cell.ParentRow;
    double price, quantity;
    object o = row.Cells[“Price”].Value;
    if (o is double) price = (double)o; else price = 0.0;
    o = row.Cells[“Quantity”].Value;
    if (o is double) quantity = (double)o; else quantity = 0.0;
    row.Cells[“Total”].Value = price * quantity;
    }</code>

    Imported from legacy forums. Posted by Tommy (had 382 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks Tommy! That worked like a charm. I had to convert it to VB.NET but it worked perfectly. Looks like you are the guy to talk to when you need answers.

    Thanks again!

    Imported from legacy forums. Posted by twlichty (had 3441 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.