User (Old forums)MemberApril 25, 2005 at 9:26 pmPost count: 23064
What I would like is for a user to DoubleClick anywhere on a row and have an event raised with the sender to be the DataRow that was clicked. I should be able to do this with the following code however the event is never raised. If I hook up for the same event on the Cell objects it will work however I should not have to go to that much trouble.
Any suggestions of what I am doing wrong here?
Xceed.Grid.DataRow datarow = _grid.DataRows.AddNew();
datarow.ReadOnly = true;
datarow.AllowCellNavigation = false;
datarow.DoubleClick +=new EventHandler( DataRow_DoubleClick );
Imported from legacy forums. Posted by Toddca (had 4293 views)User (Old forums)MemberApril 26, 2005 at 2:15 amPost count: 23064
If a row has cells (like a DataRow), and you double-click the row, you’re actually double-clicking one of the cells. So the double-clicked cell receives the DoubleClick event. I see you’re initializing each DataRow after you add it. This is not necessary: you can set properties and events on the DataRowTemplate of the grid once, and each created DataRow will automatically be initialized like this. You could do it like this:<code>_grid.DataRowTemplate.ReadOnly = true;
_grid.DataRowTemplate.AllowCellNavigation = true;
foreach(Xceed.Grid.Cell cell in _grid.DataRowTemplate.Cells)
cell.DoubleClick += new EventHandler( Cell_DoubleClick );
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;
Imported from legacy forums. Posted by Tommy (had 169 views)User (Old forums)MemberAugust 11, 2005 at 2:02 pmPost count: 23064
How can you add a DoubleClick event for each row in the grid without looping through each row? I am using DataBinding and would rather not have to loop through each row/cell.
Imported from legacy forums. Posted by a (had 262 views)User (Old forums)MemberAugust 12, 2005 at 3:09 amPost count: 23064
You use the DataRowTemplate of the grid. See one of the previous messages in this post for an example.
Imported from legacy forums. Posted by Tommy (had 233 views)User (Old forums)MemberAugust 12, 2005 at 7:51 amPost count: 23064
The code example posted by Tommy works but we really should only be newing an EventHandler object once and then assigning a reference to that single EventHandler object to each row in the template rather than newing in a foreach loop.
Imported from legacy forums. Posted by Toddca (had 341 views)User (Old forums)MemberAugust 15, 2005 at 8:03 amPost count: 23064
Yes, I usually do this too, but for examples in this forum, I always try to post code that is short and easy to understand. Using a single EventHandler, means using an extra variable. It’s good practice to do this, but I like keeping my examples simple.
Imported from legacy forums. Posted by Tommy (had 5184 views)
- You must be logged in to reply to this topic.