Home Forums WinForms controls Xceed Grid for WinForms Context menu in master/detail

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

    I have a master/detail grid created with a DataSource and need a context-menu in the master row and a different one in the detail row of the grid. I have two context-menu defined in the form

    In the click event of the grid I can assign the corresponding context-menu to the grid context-menu as i know if the click is in the master row or in the detail row.

    The click event and mousedown right button works both fine if i first click in the row and then right-click in the same row. The problem is when i am in a row and the mousedown event is fired in another row without pressing click button in that row. The result is the same context menu.

    In another hand, i have noticed that the mousedown event doesn’t get fired in all the DataRows or cells of the grid.

    How can i resolve this problems by code. I’m using c#. Thanks.

    Imported from legacy forums. Posted by Javier (had 5950 views)

    User (Old forums)
    Member
    Post count: 23064

    You could try catching the MouseDown event of the GridControl. Then, get the mouse coordinates from the MouseEventArgs, and use the GridControl.GetVisualGridElementAtPoint method to get the element at those coordinates.

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

    User (Old forums)
    Member
    Post count: 23064

    Thanks for your answer, Tommy.

    i have the following code:

    grid.BeginInit();
    grid.DataSource = DS;
    grid.DataMember = “Tablas”;
    DetailGrid detail = new DetailGrid();
    detail.HeaderRows.Add( new ColumnManagerRow() );
    detail.DataSource = null;
    detail.DataMember = “TablaDescripcion”;
    grid.DetailGridTemplates.Add( detail );
    foreach(Xceed.Grid.DataRow row in grid.DataRows)
    {
    foreach(Cell cell in row.Cells)
    cell.MouseDown += new MouseEventHandler(grid_MouseDown);
    }
    grid.MouseDown += new MouseEventHandler(grid_MouseDown);
    grid.BeginInit();

    and the event handler is

    private void grid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if (e.Button == MouseButtons.Right)
    {
    Xceed.Grid.VisualGridElement element;
    Xceed.Grid.Row row;
    element = grid.GetVisualGridElementAtPoint(e.X, e.Y);
    if (element.GetType().ToString() == “Xceed.Grid.Row”)
    row = (Xceed.Grid.Row)element;
    else
    {
    if (element.GetType().ToString() == “Xceed.Grid.Cell”)
    row = ((Xceed.Grid.Cell)element).ParentRow;
    else
    row = null;
    }
    if (row != null)
    {
    grid.CurrentRow = row; grid.CurrentRow.BringIntoView();
    grid.ContextMenu.Show(grid, new System.Drawing.Point(e.X, e.Y));
    }
    }

    If i click a row and then right-click in the same row the context menu works, i think by means of the normal processing of the context menu of the grid, because this event is not fired.

    In fact, this event is not executed in none of the cells of the grid (i put a debugger stopping point at the beginning of it and the it doesn’t enter).

    Thanks for your help.

    Imported from legacy forums. Posted by Javier (had 409 views)

    User (Old forums)
    Member
    Post count: 23064

    Try this (untested code):<code>grid.MouseDown += new MouseEventHandler(grid_MouseDown);
    private void grid_MouseDown(object sender, MouseEventArgs e) {
    if (e.Button == MouseButtons.Right) {
    VisualGridElement element = grid.GetVisualGridElementAtPoint(e.X, e.Y);
    Row row;
    if (element is Row) row = element as Row;
    else if (element is Cell) row = (element as Cell).ParentRow;
    else row = null;
    if (row != null) {
    grid.CurrentRow = row;
    row.BringIntoView();
    grid.ContextMenu.Show(grid, new Point(e.X, e.Y));
    }
    }
    }</code>

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

    User (Old forums)
    Member
    Post count: 23064

    Thanks for your reply, Tommy, but i can’t see the difference between your code and the one i wrote in my last post, code that, at least for me, doesn’t work, maybe i’m missing something.

    Imported from legacy forums. Posted by Javier (had 262 views)

    User (Old forums)
    Member
    Post count: 23064

    If you call <i>element.GetType().ToString()</i> on a DataRow, it will return “Xceed.Grid.DataRow”, and not “Xceed.Grid.Row”.
    If you call <i>element is Row</i>, true will be returned for all the classes that inherit from Row.

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

    User (Old forums)
    Member
    Post count: 23064

    thanks Tommy, i’ll try this changes next monday.

    Imported from legacy forums. Posted by Javier (had 417 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Tommy, i’ve tried the modifications and the problem is still active. When in debug mode i see the type that element is, it returns DataRow or RowSelector or ColumnManagerCell depending the place of the click on the grid, and then i can’t found or i don’t know the way to determine the current row where i have done the click event.

    Another problem is that the MouseDown event is not fired in all the cells or rows of the grid. As an example, if i right-click on the actual current row, this event is not fired.

    Thanks.

    Imported from legacy forums. Posted by Javier (had 571 views)

    User (Old forums)
    Member
    Post count: 23064

    Then I’m sorry, but I don’t really see what might cause this problem. I think you should contact Xceed’s Technical Support.

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

    User (Old forums)
    Member
    Post count: 23064

    Tommy,

    i have solved the problem using the sender object of the MouseDown event.

    after grid.EndInit():

    foreach(Xceed.Grid.DataRow row in grid.DataRows)
    {
    foreach(Cell cell in row.Cells)
    cell.MouseDown += new MouseEventHandler(Data_MouseDown);
    foreach(Xceed.Grid.DataRow drow in row.DetailGrids[0].DataRows)
    {
    foreach(Cell dcell in drow.Cells)
    dcell.MouseDown += new MouseEventHandler(Data_MouseDown);
    }
    }

    an Data_MouseDown is:

    if (e.Button == MouseButtons.Right)
    {
    Xceed.Grid.Row row = null;
    row = ((Xceed.Grid.DataCell)sender).ParentRow;
    if (row != null)
    {
    if (row.CanBeCurrent)
    {
    grid.CurrentRow = row; grid.CurrentRow.BringIntoView();
    grid.SelectedRows.Clear();
    grid.CurrentRow.IsSelected = true;
    //Assing grid.ContextMenu based on CurrentRow (other code)
    }
    }
    }

    I don’t Know how to capture the MouseDown event in the Headers of the master and detail rows, but that is another problem.

    Thanks for all.

    Imported from legacy forums. Posted by Javier (had 7362 views)

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