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

How to get event for click on row Header

2 Answers 93 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dominik
Top achievements
Rank 1
Dominik asked on 14 Sep 2011, 04:03 PM
Hi

In our Silverlight 4 application we use a double click on a grid Viewcell to select all cells of the concerned row.  Example:


public class CustomGrid : RadGridView
    {
        public CustomGrid()
            : base()
        {
                this.AddHandler(GridViewCellBase.CellDoubleClickEvent, new EventHandler<RadRoutedEventArgs>(OnCellDoubleClick), true);
        }
 
 
       
 
   private void OnCellDoubleClick(object sender, RadRoutedEventArgs args)
        {
            if (this.GridMode == EGridMode.EditCells)
            {
                var cell = args.OriginalSource as GridViewCellBase;
                if (cell != null && cell.ParentRow != null)
                {
                    var row = cell.ParentRow;
                    this.CurrentItem = row.Item;
                }
            }
        }



This works fine. However, some rows in the grid are disabled and the double click event will not execute. Is there a way to catch the event when the row header is clicked (and to get to the item/row)? This would be great.

(This functionality is needed because we have more than 60 - sometimes broad - columns. The use need a way to mark a row when he is scrolling vertically, otherwise he is lost. Selecting the entire row by setting the Current item  has proven to work very well. Unfortunately, this does not work when the row is disabled. It would be ok to select the current item, so this is only displayed in the row header. )

Greetings and thanks in advance







2 Answers, 1 is accepted

Sort by
0
Dominik
Top achievements
Rank 1
answered on 15 Sep 2011, 03:05 PM
Does anyone have an idea?
0
Dominik
Top achievements
Rank 1
answered on 17 Sep 2011, 01:01 PM
 
I have found a workaround for my problem. I no longer disable entire rows but i make them fully readonly by using custom columns :

public class CustomDataColumn : GridViewDataColumn
   {
       public IbsCustomDataColumn()
           : base()
       {
 
       }
 
       public override void OnPastingCellClipboardContent(object item, object value)
       {
           // to check
           if (IbsCustomDataColumn.IsItemEditable(item))
           {
               base.OnPastingCellClipboardContent(item, value);
           }
       }
 
 
       public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)
       {
           var grid = this.DataControl as CustomGrid;
           if (!grid.IsReadOnly)
           {
               if (!IbsCustomDataColumn.IsItemEditable(dataItem))
               {
                   var toReturn = base.CreateCellEditElement(cell, dataItem);
                   if (toReturn is TextBox)
                   {
                       ((TextBox)toReturn).IsReadOnly = true;
                   }
                   else if (toReturn is Control)
                   {
                       ((Control)toReturn).IsEnabled = false;
                   }
                   return toReturn;
               }
           }
           return base.CreateCellEditElement(cell, dataItem);
       }
 
       
 
       public static bool IsItemEditable(object dataItem)
       {
           // perorm some logic here
           return true;
       }

(I also did a similar thing for different types of columns (combobox...)

Maybe there is a better a way, but i works quite well.
Tags
GridView
Asked by
Dominik
Top achievements
Rank 1
Answers by
Dominik
Top achievements
Rank 1
Share this question
or