This is a migrated thread and some comments may be shown as answers.

BeginEditMode, Cell Editing and Tab key problems

4 Answers 600 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ali Mohamad
Top achievements
Rank 1
Ali Mohamad asked on 01 Apr 2010, 12:15 AM
Telerik.Win.Control.UI.dll version is "2009.3.9.1203"

Hi,
I am running into several behavior problems with the RadGridView control. 
1)  If I set the BeginEditMode to "BeginEditOnF2", the user is still able to get into edit mode by double-clicking on a cell - not what is expected! 
2) once the grid is in edit mode, the user can click on another cell to put it in edit mode regardless of the BeginEditMode setting
3) worst yet, if the user is editing a cell and hit the tab (or shift-tab), the new cell goes into edit mode but the changes to the original cell are not submitted to the bound dataset even though the CellEndEdit event is called (where I update the dataset).  Code is below...

Any help would be greatly appreciated...
Ali M.

In the code below, I was forced to ignore the BeginEditMode property because it is not working and instead implemented a CellDoubleClick event handler that puts the cell into edit mode.  If the user makes a change and hits the Enter key, then changes are submitted to the db in the CellEndEdit event handler.  But, if the user tabs to another cell, the cell is put into Edit mode but the changes he/she made in the previous cell are not submitted...
My preferred solution would be to enforce the F2-only edit mode through the BeginEditMode property...


Public Class RadForm1 
    Private _cellModifyBegin As Boolean 
    Private _currentEditCell As Integer 
 
    Private Sub RadForm1_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load 
        _cellModifyBegin = False 
 
        Try 
            grdCustomers.EnterKeyMode = Telerik.WinControls.UI.RadGridViewEnterKeyMode.None 
            Me.CustomerTableAdapter.Fill(Me.CustomerApps.Customer) 
        Catch ex1 As System.Exception 
            Debug.WriteLine(String.Format("Failed in frmMain2.frmMain2_Load - Exception: {0}", ex1.ToString())) 
            My.Application.Log.WriteException(ex1) 
            MessageBox.Show(String.Format("An error has ocurred. Message : {0}", ex1.Message())) 
        Finally 
            Debug.WriteLine("End ---> frmMain2.frmMain2_Load"
            My.Application.Log.WriteEntry(String.Format("End --->     {0:00}:{1:00}:{2:00}:{3:0000}   frmMain2.frmMain2_Load", Now.Hour, Now.Minute, Now.Second, Now.Millisecond)) 
        End Try 
    End Sub 
 
    Private Sub grdCustomers_CellBeginEdit(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.GridViewCellCancelEventArgs) Handles grdCustomers.CellBeginEdit 
        Debug.Print(String.Format("grdCustomers_CellBeginEdit.  RowIndex={0}, CellIndex={1}", e.RowIndex, e.ColumnIndex)) 
        If _currentEditCell <> e.ColumnIndex Then 
            ' this cell got into Edit mode due to user tabbing away from a previous cell edit 
            e.Cancel = True 
            Return 
        End If 
        _cellModifyBegin = True 
    End Sub 
 
    Private Sub grdCustomers_CellDoubleClick(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles grdCustomers.CellDoubleClick 
        Debug.Print(String.Format("grdCustomers_CellDoubleClick.  RowIndex={0}, CellIndex={1}", e.RowIndex, e.ColumnIndex)) 
        _currentEditCell = e.ColumnIndex 
        e.Row.Cells(e.ColumnIndex).BeginEdit() 
    End Sub 
 
    Private Sub grdCustomers_CellEndEdit(ByVal sender As ObjectByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles grdCustomers.CellEndEdit 
        If grdCustomers.ActiveEditor.IsModified Then 
            Debug.Print(String.Format("grdCustomers_CellEndEdit.  RowIndex={0}, CellIndex={1}", e.RowIndex, e.ColumnIndex)) 
            CustomerTableAdapter.Update(CustomerApps.Customer) 
            grdCustomers.Update() 
        End If 
        _cellModifyBegin = False 
    End Sub 
End Class 

4 Answers, 1 is accepted

Sort by
0
Ali Mohamad
Top achievements
Rank 1
answered on 06 Apr 2010, 05:38 PM
Bump... I really do need a response to this issue.

Thank you
Ali
0
Svett
Telerik team
answered on 07 Apr 2010, 08:44 AM
Hello Ali Mohamad,

The described scenario is the default behavior of the grid. Only the RadGridViewBeginEditMode.BeginEditProgrammatically mode prevents going in edit mode when double clicked is performed. You can create a custom grid behavior where you can customize the grid behavior in your own way. You can read more about events that you can handle in this documentation article.

You can use the following code snippet as basis:

public class MyBaseGridBehavior: BaseGridBehavior
{
    protected override bool OnMouseDownLeft(System.Windows.Forms.MouseEventArgs e)
    {
        return base.OnMouseDownLeft(e);
    }
 
    // ...
 
    private GridRowElement GetRowAtPoint(Point mouseLocation)
    {
        RadElement elementUnderMouse = this.GridControl.ElementTree.GetElementAtPoint(mouseLocation);
 
        while (elementUnderMouse != null)
        {
            if (elementUnderMouse is GridRowElement)
            {
                return elementUnderMouse as GridRowElement;
            }
 
            elementUnderMouse = elementUnderMouse.Parent;
        }
 
        return null;
    }
 
    private GridCellElement GetCellAtPoint(Point mouseLocation)
    {
        RadElement elementUnderMouse = this.GridControl.ElementTree.GetElementAtPoint(mouseLocation);
 
        while (elementUnderMouse != null)
        {
            if (elementUnderMouse is GridCellElement)
            {
                return elementUnderMouse as GridCellElement;
            }
 
            elementUnderMouse = elementUnderMouse.Parent;
        }
 
        return null;
    }
}

You need to replace the default behavior with the following code:

this.radGridView.GridBehavior = new MyBaseGridBehavior();

Greetings,
Svett
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
aryz
Top achievements
Rank 1
answered on 02 Nov 2010, 02:10 PM
well i have the same issue here

in my radgridview.... i try to change a cell in a single row collection.... but when i press an update button which is look like these :
_Conn = new MySqlConnection("SERVER=[domain];DATABASE=[database name]UID=[username];PASSWORD=[password]; Allow Zero Datetime=FALSE; ");
            string SQL = "SELECT * FROM [tablename]"
            _Adap = new MySqlDataAdapter(SQL,_Conn);
            MySqlCommandBuilder _CmdBuild = new MySqlCommandBuilder(_Adap);
            _Dataset = new DataSet();
            _Adap.Fill(_Dataset, tablename);
            radGridView1.DataSource = _Dataset;
            radGridView1.DataMember = [tablename];
with action update button:
try
{
    _Adap.Update(_Dataset, [tablename]);
}
catch (Exception ex)
{
    RadMessageBox.Show(this, ex.Message, this.Text, MessageBoxButtons.OK, RadMessageIcon.Error);
}

the radgrid is not commited any changes [modified] row to dataset. would you mind to point me a clue.


0
Svett
Telerik team
answered on 05 Nov 2010, 03:37 PM
Hello aryz,

Did you try invoking the EndEdit method of RadGridView before saving your changes to the data base? Generally, I would recommend upgrading to the latest version Q2 2010 SP2 (2010.2 10.914) where many issues have been addressed. 

Greetings,
Svett
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Ali Mohamad
Top achievements
Rank 1
Answers by
Ali Mohamad
Top achievements
Rank 1
Svett
Telerik team
aryz
Top achievements
Rank 1
Share this question
or