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

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

5 Answers 84 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dan Weese
Top achievements
Rank 1
Dan Weese asked on 15 Mar 2010, 10:26 PM
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?

5 Answers, 1 is accepted

Sort by
0
Accepted
Milan
Telerik team
answered on 16 Mar 2010, 07:40 AM
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.
0
Dan Weese
Top achievements
Rank 1
answered on 16 Mar 2010, 08:28 PM
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?
0
Milan
Telerik team
answered on 18 Mar 2010, 05:43 PM
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.
0
Greg
Top achievements
Rank 1
answered on 10 Jun 2013, 07:52 PM
Hi Milan. 

Did you guys ever implement a multi cell select functionality that you mentioned above? 
0
Maya
Telerik team
answered on 11 Jun 2013, 06:30 AM
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.

Tags
GridView
Asked by
Dan Weese
Top achievements
Rank 1
Answers by
Milan
Telerik team
Dan Weese
Top achievements
Rank 1
Greg
Top achievements
Rank 1
Maya
Telerik team
Share this question
or