radGridView Total and limit value

2 posts, 0 answers
  1. Jesús
    Jesús avatar
    1 posts
    Member since:
    Jan 2013

    Posted 14 Feb 2013 Link to this post

    Hi

    I have this scene, one mask edit with integer limit quantity. One radgrid for introducing any number of row. 3 Columns. (2 dropdown, one decimal column)

    our users can write data if the quantity  is less than limit quantity. If the summatory of the grid and the current row is over the limit i want cancel this new line. How can do this?

    In this grid, too, we have 2 raddropdown list editor, for the autocomplete mode. But we want to limit to the existing data. If the data don't not exist the user can't leave the current cell. It is possible? How?

    tx in advanced.

    Jesús.

  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 19 Feb 2013 Link to this post

    Hi Jesus,

    Thank you for writing.

    1) You can cancel adding a new row in RadGridView by using the
    UserAddingRow event handler:
    void gridView_UserAddingRow(object sender, GridViewRowCancelEventArgs e)
    {
        if (e.Rows.Length > 0 && e.Rows[0] is GridViewNewRowInfo)
        {
            GridViewNewRowInfo rowInfo = e.Rows[0] as GridViewNewRowInfo;
            if (rowInfo.Cells["id"].Value == null && rowInfo.Cells["number"].Value.ToString() == "111")
            {
                e.Cancel = true;
            }
        }
    }

    2) You can use CellValidating event to implement this functionality:
    void radGridView1_CellValidating(object sender, Telerik.WinControls.UI.CellValidatingEventArgs e)
    {
        GridViewDataColumn column = e.Column as GridViewDataColumn;
        if (e.Row is GridViewDataRowInfo && column != null && column.Name == "CategoryName")
        {
            if (string.IsNullOrEmpty((string)e.Value) || ((string)e.Value).Trim() == string.Empty)
            {
                e.Cancel = true;
                ((GridViewDataRowInfo)e.Row).ErrorText = "Validation error!";
            }
            else
            {
                ((GridViewDataRowInfo)e.Row).ErrorText = string.Empty;
            }
        }
    }

    More information about this topic you can find in our online documentation.

    I hope this helps.

    Regards,
    Julian Benkov
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Back to Top