Home Forums WinForms controls Xceed Grid for WinForms Double click on grid??

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

    Hi I’m trying to get the double click event to be raised on a grid; I have the following code to bind my grid:

    Customer c = new Customer();
    foreach (Xceed.Grid.Cell cell in gridOrderHistory.DataRowTemplate.Cells)
    cell.DoubleClick += new EventHandler(Cell_DoubleClick);

    this.gridOrderHistory.DataSource = c.GetCustomerOrderHistory(2).Tables[0].DefaultView;

    I then have the event:

    private void Cell_DoubleClick(object sender, EventArgs e)
    {
    Xceed.Grid.Cell cell = sender as Xceed.Grid.Cell;
    Xceed.Grid.DataRow row = cell.ParentRow as Xceed.Grid.DataRow;
    }

    But when I run this, my data is bound ok to the grid but I double click does not work?

    What am I doing wrong?

    Thanks

    Imported from legacy forums. Posted by ric (had 2933 views)

    User (Old forums)
    Member
    Post count: 23064

    Is your grid ReadOnly? If so, this should work fine.

    If not, however, the double click event will be on the editor of the cell, not on the cell itself. Here is what you need to do to get the double click event. This code snippet assumes cells are of string data type, thus using a simple TextBoxEditor.

    You need to subscribe to TextBox events through the ActivatingControl event of the CellEditorManager. This is necessary because the editor is actually initialized only when the cell receives focus, and enters the edit mode.

    e.g.:

    //at Form_Load
    <i>
    private void Form1_Load(object sender, System.EventArgs e)
    {
    gridControl1.Columns[ 0 ].CellEditorManager.ActivatingControl += new CellEditorEventHandler(CellEditorManager0_ActivatingControl);
    gridControl1.Columns[ 0 ].CellEditorManager.DeactivatingControl += new CellEditorEventHandler(CellEditorManager0_DeactivatingControl);
    </i>
    //Event Handlers
    <i>
    private void CellEditorManager0_ActivatingControl(object sender, CellEditorEventArgs e)
    {
    ( ( WinTextBox )e.Control).TextBoxArea.DoubleClick += new EventHandler(TextBoxArea_DoubleClick);
    }

    private void CellEditorManager0_DeactivatingControl(object sender, CellEditorEventArgs e)
    {
    //need to unsubscribe, if not, the subscriptions will kept pilling up!
    ( ( WinTextBox )e.Control).TextBoxArea.DoubleClick -= new EventHandler(TextBoxArea_DoubleClick);
    }

    private void TextBoxArea_DoubleClick(object sender, EventArgs e)
    {
    System.Diagnostics.Debug.WriteLine( sender.ToString() );
    }
    </i>

    Imported from legacy forums. Posted by André (had 347 views)

    User (Old forums)
    Member
    Post count: 23064

    I want to use this code for VB.NET and the CellEditorManager doesn’t have ActivatingControl and DeactivatingControl properties. Please advise.

    Imported from legacy forums. Posted by Milo (had 281 views)

    User (Old forums)
    Member
    Post count: 23064

    You need to use the AddHandler method rather then the “+=” in C#.

    e.g.:

    //at Form_Load
    <i>
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    AddHandler GridControl1.Columns( 0 ).CellEditorManager.ActivatingControl, AddressOf CellEditorManager_ActivatingControl
    AddHandler GridControl1.Columns( 0 ).CellEditorManager.DeactivatingControl, AddressOf CellEditorManager_DeactivatingControl

    End Sub
    </i>

    //Event handlers :
    <i>
    Private Sub CellEditorManager_ActivatingControl( ByVal sender As Object, ByVal e As Xceed.Grid.Editors.CellEditorEventArgs )

    Dim editor as Xceed.Editors.WinTextBox = CType( e.Control, Xceed.Editors.WinTextBox)
    AddHandler editor.TextBoxArea.TextChanged, AddressOf editor_TextChanged

    End Sub

    Private Sub CellEditorManager_DeactivatingControl( ByVal sender As Object, ByVal e As Xceed.Grid.Editors.CellEditorEventArgs )

    Dim editor as Xceed.Editors.WinTextBox = CType( e.Control, Xceed.Editors.WinTextBox)
    ‘this needs to be done, if not, subscriptions will pill up every time the editor is activated
    RemoveHandler editor.TextBoxArea.TextChanged, AddressOf editor_TextChanged

    End Sub

    Private sub editor_TextChanged(ByVal sender As System.Object, ByVal e As EventArgs )

    Dim value as String = CType( sender, TextBoxArea ).Text

    End Sub
    </i>

    Imported from legacy forums. Posted by André (had 4119 views)

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