Playing Chicken With Common Sense

I am working on a WPF project at work and we purchased a couple components from a couple of different component vendors.  One of them is ComponentOne and we have used the C1DataGrid in several places.  Recently a bug was submitted that said they could not tab or shift tab through the grid and have it select the next or previous row automatically when the beginning or end of the row is hit.

What I discovered was that we shouldn’t have picked ComponentOne for our data grid because they have terrible support and their component is pretty average.  We would have been better off just using faking a grid but when we bought it Microsoft had not put out their data grid and we didn’t want to roll our own.

Now if you are unfortunate enough to have purchased the ComponentOne DataGrid and are looking for a way to make the grid act like most other grids on the planet then here is how I did it.

Implement a KeyUp event on your grid.

private void c1DataGrid1_KeyUp(object sender, KeyEventArgs e)
{
    if (c1DataGrid1.SelectedGridItem == null || c1DataGrid1.SelectedItemCellPresenter == null)
        return;
 
    var columnName = c1DataGrid1.SelectedItemCellPresenter.ColumnName;
    var column = c1DataGrid1.SelectedGridItem.Row.Cells[columnName].Column;
    var columnIndex = c1DataGrid1.ActualColumns.IndexOf(column);
    var rowIndex = c1DataGrid1.Rows.IndexOf(c1DataGrid1.SelectedGridItem.Row);
    var a = string.Format("Column Name of Selected Cell: {0}", columnName);
    var b = string.Format("Selected Cell Value: {0}", c1DataGrid1.SelectedGridItem.Row.Cells[columnName].Value);
 
    KeyEventArgs keyEventArgs = e;
    if (keyEventArgs == null) return;
 
    if (columnName == "FirstName" && (keyEventArgs.Key == Key.Tab && Keyboard.Modifiers == ModifierKeys.Shift))
    {
        if(_firstColumnCount > 0)
        {
            _blcv.MoveCurrentToPrevious();
        }
        ++_firstColumnCount;
        _lastColumnCount = 0;
    }
    else if (columnName == "LastName" && (keyEventArgs.Key == Key.Tab && Keyboard.Modifiers == ModifierKeys.None))
    {
        if(_lastColumnCount > 0)
        {
            _blcv.MoveCurrentToNext();
        }
        ++_lastColumnCount;
        _firstColumnCount = 0;
    }
}

 

You will need a backing store object as so:

private BindingListCollectionView _blcv;

The other thing to note is that you will want to know if the shift key is being pressed at the same time.  It isn’t provided by C1 so look to the WPF framework for the Keyboard class.  You can test if shift is being pressed as follows:

Keyboard.Modifiers == ModifierKeys.Shift

Hopefully, this has helped you find your way out of darkness and into the light. ;)

  • 2 Comments
  • E-mail
  • Kick it!
  • Shout it
  • Bookmark and Share

Comments

trackback DotNetShoutout    7/1/2009 12:33:17 PM #

wijix | WPF C1DataGrid how to tab or shift tab

Thank you for submitting this cool story - Trackback from DotNetShoutout

trackback DotNetKicks.com    7/1/2009 12:33:43 PM #

WPF C1DataGrid how to tab or shift tab

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Control panel

RecentComments

Comment RSS