Tuesday, September 16, 2014

Selecting a row/record in Syncfusion's GridGroupingControl manually or at runtime

Here are following steps to select a row in gridgroupingcontrol manually:

1 - // Set  these properties
     //Inherited GridControlBase Selection

//turn on the GridGroupingControl's listbox mode (uses Table.SelectRecords collection)
            gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.One; 
//turn off GridControlBase selection support (do not use TableControl.Selections collection
      gridGroupingControl1.TableOptions.AllowSelection = ((Syncfusion.Windows.Forms.Grid.GridSelectionFlags)((Syncfusion.Windows.Forms.Grid.GridSelectionFlags.Row | Syncfusion.Windows.Forms.Grid.GridSelectionFlags.AlphaBlend)));
        //indicate how you want current cell to look/behave
            gridGroupingControl1.TableOptions.ListBoxSelectionCurrentCellOptions = GridListBoxSelectionCurrentCellOptions.HideCurrentCell;

2 - // Call this function on button click or on some other event
  private void SetGridRow()
        {
            gridGroupingControl1.Table.Records[0].SetCurrent();
            gridGroupingControl1.TableControl.CurrentCell.Activate(0, 0);
        }

3 - Implement this event and it will raise automatically due to step 2
        private void gridGroupingControl1_TableControlCurrentCellActivated(object sender, GridTableControlEventArgs e)
        {
            GridGroupingControl grid = sender as GridGroupingControl;

            if (grid.Table.CurrentRecord != null)
            {
                grid.Table.SelectedRecords.Clear();
                Record rec = grid.Table.CurrentRecord;
                if (!grid.Table.SelectedRecords.Contains(rec))
                    grid.Table.SelectedRecords.Add(rec);
            }            
        }

5 comments:

  1. which programming language code is this how can I implement this??
    PATCH | CRACK

    ReplyDelete
  2. What if we want to set focus on newly addded row..??

    ReplyDelete
    Replies
    1. This has been our development team's problem with Syncfusion,

      Delete
  3. I am using GridGroupingControl (Windows forms), where user is able to add new records in the grid.
    I am having following code, this works well when user enters all the values but when user leave something blank, validation doesn't fire.
    private void gridGroupingControl1_CurrentRecordContextChange(object sender, Syncfusion.Grouping.CurrentRecordContextChangeEventArgs e)
    {
    if(e.Action == Syncfusion.Grouping.CurrentRecordAction.EndEditComplete)
    {
    SqlHelper.UpdateWithAdapter(ds, "getCustomers");
    ds.AcceptChanges();
    }
    }

    private void gridGroupingControl1_TableControlCurrentCellValidating(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCancelEventArgs e)
    {
    --This is firing only for when I enter something in cell, but when user hits enter on other cell, gridGroupingControl1_CurrentRecordContextChange is called and trying to save null and giving exception
    }

    Can you help me out?

    ReplyDelete