Best way to trap mouse down/drag over a group of cells?

6 posts, 1 answers
  1. Dan Weese
    Dan Weese avatar
    16 posts
    Member since:
    Sep 2009

    Posted 15 Mar 2010 Link to this post

    I have a grid with 49 columns. Column 1 is the day of the week, and the rest of the columns are the time of day in 30 minute increments. What I'm trying to accomplish is when I click and drag across several cells, I want to change the back color of any cell I drag over. What is the best way to accomplish this with the radGridView?
  2. Answer
    Milan
    Admin
    Milan avatar
    1989 posts

    Posted 16 Mar 2010 Link to this post

    Hello Dan Weese,

    Currently this will not be an easy task but we are working on multiple cell selection mechanism which will automatically do that for you. This new feature should be available in our next service pack release.

    Hope this information if helpful.


    Greetings,
    Milan
    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.
  3. Dan Weese
    Dan Weese avatar
    16 posts
    Member since:
    Sep 2009

    Posted 16 Mar 2010 Link to this post

    OK, Can you tell me the best way to capture clicking on a single grid cell? The grid is read only. I have the colors setting fine on the GotFocus event, but if the user clicks the cell, then clicks it again, it already has the focus so that event doesn't fire again. They would have to move off, click another cell, then go back to the first cell and click again to remove the back color. I tried MouseDown, MouseUp, MouseLeftButtonDown, MouseLeftButtonUp. but those required the grid not be read only.

    It also appears that as soon as the cells scroll out of the visible pane, they lose their color. I'm assuming I'll have to set a boolean value or something like that to keep the colors in the cells?
  4. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 18 Mar 2010 Link to this post

    Hello Dan Weese,

    RadGridView is handling many mouse and keyboard events and most probably that is the reason why you haven't been able to receive those event. Nevertheless there is a way to subscribe for those event using the AddHandler method:

    public Window1()
    {
        InitializeComponent();
      
        this.playersGrid.ItemsSource = Club.GetPlayers();
        this.playersGrid.RowLoaded += new System.EventHandler<RowLoadedEventArgs>(playersGrid_RowLoaded);
    }
      
    void playersGrid_RowLoaded(object sender, RowLoadedEventArgs e)
    {
        var row = e.Row as GridViewRow;
      
        if (row != null)
        {
            foreach (var cell in row.Cells)
            {
                cell.AddHandler(GridViewCell.MouseLeftButtonDownEvent, 
                    new MouseButtonEventHandler(OnCellMouseDown), true);
            }
        }
    }
      
    private void OnCellMouseDown(object sender, MouseButtonEventArgs e)
    {
        var clickedCell = (GridViewCell)sender;
    }

    In regards to the second issue you should to set EnableColumnVirtualization and EnableRowvirtualization to false if you would like the cells to persist their colors. 

    Kind regards,
    Milan
    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.
  5. Greg
    Greg avatar
    7 posts
    Member since:
    Oct 2012

    Posted 10 Jun 2013 Link to this post

    Hi Milan. 

    Did you guys ever implement a multi cell select functionality that you mentioned above? 
  6. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 11 Jun 2013 Link to this post

    Hi Greg,

    We have implemented multiple cell selection a long time ago. You can test the functionality on our demos and read more about it in the documentation.
    Let us know if you need any assistance with that.

     

    Regards,
    Maya
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top