Hide rectangle while click on cell && Select 1st row for 1st group

[1] Hide rectangle while click on cell, when i click on cell it is showing current cell selected but my requirement is display row as selected & don't want to display cell selected.
[2] On Page Load 1st row for 1st group should be by default selected.
[3] Don't want to show expand column for groups, as i have all the groups expanded by default, also group should not be collapsed.
[4] TableSummaryRow X location to changed to same as GroupSummary Row.(i e. If i have group summary for 3rd column Then TableSummaryRow  should be displayed
      in 3rd Column )
[5] When moving through grid don't want TableSummaryRow , GroupSummaryRow OR CaptionSummaryRow to selected(ie. From last row of Group(expect
      GroupSummaryRow ) selection should move to next group first row.)
[6] Require CaptionSummaryRow {Key}value For Group in GroupSummaryRow


13 Replies

DY Deivaselvan Y Syncfusion Team October 8, 2018 12:59 PM UTC

Hi Avinash, 
 
Thanks for contacting Syncfusion support. 

Query 
Solution 
Hide rectangle while click on cell, when i click on cell it is showing current cell selected but my requirement is display row as selected & don't want to display cell selected. 
This can be achieved by setting SfDataGrid.NavigationMode as Row. Please refer to the following code example. 

Code Example:  

this.sfDataGrid.NavigationMode = NavigationMode.Row; 


On Page Load 1st row for 1st group should be by default selected. 
You can move the selection to any row on page load by using the SfDataGrid.MoveToCurrentCell method within the Form.Load event. 
Please refer to the following code example. 

Code example :  
this.Load += Form1_Load; 

void Form1_Load(object sender, System.EventArgs e) 
{ 
    this.sfDataGrid.MoveToCurrentCell(new RowColumnIndex(1, 1)); 
} 


Don't want to show expand column for groups, as i have all the groups expanded by default, also group should not be collapsed. 
To hide the indent column set the SfDataGrid.IndentColumnWidth property to 0 before grouping a column. Please refer to the following code example. 


Code Example : 

this.sfDataGrid.IndentColumnWidth = 0; 


Collapsing and expanding the group can be avoided by using SfDataGrid.GroupExpanding and SfDataGrid.GroupCollapsing events. Please refer to the following code example. 

this.sfDataGrid.GroupExpanding += sfDataGrid_GroupExpanding; 
this.sfDataGrid.GroupCollapsing += sfDataGrid_GroupCollapsing; 

void sfDataGrid_GroupCollapsing(object sender, Syncfusion.WinForms.DataGrid.Events.GroupChangingEventArgs e) 
{ 
    e.Cancel = true; 
} 
 
void sfDataGrid_GroupExpanding(object sender, Syncfusion.WinForms.DataGrid.Events.GroupChangingEventArgs e) 
{ 
    e.Cancel = true; 
} 

UG Links :  
 

TableSummaryRow X location to changed to same as GroupSummary Row. (i e. If i have group summary for 3rd column Then TableSummaryRow  should be displayed  
      in 3rd Column ) 
You can achieve this by adding the group summary and table summary for the same column. Please refer to the following code example. 

Code Example :  

GridTableSummaryRow tableSummaryRow1 = new GridTableSummaryRow(); 
tableSummaryRow1.Name = "TableSummary"; 
tableSummaryRow1.ShowSummaryInRow = false; 
tableSummaryRow1.Position = VerticalPosition.Bottom; 
 
GridSummaryColumn summaryColumn1 = new GridSummaryColumn(); 
summaryColumn1.Name = "ProductName"; 
summaryColumn1.SummaryType = SummaryType.CountAggregate; 
summaryColumn1.Format = "Total Product Count: {Count}"; 
summaryColumn1.MappingName = "ProductName"; 
 
tableSummaryRow1.SummaryColumns.Add(summaryColumn1); 
 
this.sfDataGrid.TableSummaryRows.Add(tableSummaryRow1); 
 
 
GridSummaryRow groupSummaryRow1 = new GridSummaryRow(); 
groupSummaryRow1.Name = "GroupSummary"; 
groupSummaryRow1.ShowSummaryInRow = false; 
 
 
// Adds the GridSummaryColumn in SummaryColumns collection. 
groupSummaryRow1.SummaryColumns.Add(summaryColumn1); 
 
// Adds the summary row in the GroupSummaryRows collection. 
this.sfDataGrid.GroupSummaryRows.Add(groupSummaryRow1); 


When moving through grid don't want TableSummaryRow , GroupSummaryRow OR CaptionSummaryRow to selected(ie. From last row of Group(expect  
      GroupSummaryRow ) selection should move to next group first row.) 
This can also be achieved by using the SfDataGrid.MoveToCurrentCell method within the SfDataGrid.SelectionChanging event. Please refer to the following code example. 

Code Example :  

this.sfDataGrid.SelectionChanging += sfDataGrid_SelectionChanging; 

void sfDataGrid_SelectionChanging(object sender, Syncfusion.WinForms.DataGrid.Events.SelectionChangingEventArgs e) 
{ 
    var item = e.AddedItems[e.AddedItems.Count - 1] as SelectedRowInfo; 
 
    if (item != null && item.IsCaptionRow) 
    { 
        e.Cancel = true; 
        var group = (item.NodeEntry as Group); 
        if (group.GetRecordIndex(group.Records[group.Records.Count - 1]) > this.sfDataGrid.CurrentCell.RowIndex) 
            this.sfDataGrid.MoveToCurrentCell(new RowColumnIndex(this.sfDataGrid.CurrentCell.RowIndex + 1, this.sfDataGrid.CurrentCell.ColumnIndex)); 
        else  
            this.sfDataGrid.MoveToCurrentCell(new RowColumnIndex(this.sfDataGrid.CurrentCell.RowIndex - 2, this.sfDataGrid.CurrentCell.ColumnIndex)); 
    } 
    if (item != null && item.IsGroupSummaryRow) 
    { 
        e.Cancel = true; 
        if (!IsLastGroup(item.NodeEntry.Parent as Group)) 
            this.sfDataGrid.MoveToCurrentCell(new RowColumnIndex(this.sfDataGrid.CurrentCell.RowIndex + 2, this.sfDataGrid.CurrentCell.ColumnIndex)); 
    } 
} 


Require CaptionSummaryRow {Key}value For Group in GroupSummaryRow 
This can be achieved by changing the display text of the GroupSummary within the SfDataGrid.DrawCell event. Please refer to the following code example. 

Code Example: 

this.sfDataGrid.DrawCell += sfDataGrid_DrawCell; 
 
void sfDataGrid_DrawCell(object sender, Syncfusion.WinForms.DataGrid.Events.DrawCellEventArgs e) 
{ 
    if (e.DataRow.RowType == RowType.SummaryRow || e.DataRow.RowType == RowType.SummaryCoveredRow) 
    { 
        var columnName = this.sfDataGrid.GroupColumnDescriptions.FirstOrDefault(item=>item.ColumnName == e.Column.MappingName); 
 
        if(columnName != null && e.Column.MappingName == columnName.ColumnName) 
        { 
            e.DisplayText = ((e.DataRow.RowData as SummaryRecordEntry).Parent as Group).Key.ToString(); 
        } 
    } 
} 





Regards,
Deivaselvan 



AV Avinash October 15, 2018 11:11 AM UTC

When moving through grid don't want TableSummaryRow , GroupSummaryRow OR CaptionSummaryRow to selected(ie. From last row of Group(expect  
 GroupSummaryRow ) selection should move to next group first row.)
It is working fine when going down, but when moving up using up arrow key. it's get stuck at some row.

Update me how can i show this issue to you ?
 


DY Deivaselvan Y Syncfusion Team October 16, 2018 05:00 AM UTC

Hi Avinash, 

Thanks for your update. 

We suspect that increasing/decreasing the row index in the SelectionChanging event may be the cause for the failure. However we can provide another proper workaround to achieve your requirement by creating a custom SelectionController and handling the arrow key navigation within the ProcessArrowKeysForSingleMultipleSelection method. Please refer to the following code example and sample from the given location. 

Code Example : 

public Form1() 
{ 
    InitializeComponent(); 
    this.sfDataGrid.SelectionController = new CustomRowSelectionController(this.sfDataGrid); 
} 
 
 
public class CustomRowSelectionController : RowSelectionController 
{ 
    SfDataGrid DataGrid; 
 
    public CustomRowSelectionController(SfDataGrid sfDataGrid) 
        : base(sfDataGrid) 
    { 
        this.DataGrid = sfDataGrid; 
    } 
 
    protected override void ProcessArrowKeysForSingleMultipleSelection(KeyEventArgs args) 
    { 
        if (args.KeyCode == Keys.Up) 
        { 
            this.DataGrid.MoveToCurrentCell(new RowColumnIndex(this.GetPreviousRecordRowIndex(this.DataGrid.CurrentCell.RowIndex), this.DataGrid.CurrentCell.ColumnIndex)); 
        } 
        else if (args.KeyCode == Keys.Down) 
        { 
            this.DataGrid.MoveToCurrentCell(new RowColumnIndex(this.GetNextRecordRowIndex(this.DataGrid.CurrentCell.RowIndex), this.DataGrid.CurrentCell.ColumnIndex)); 
        } 
        else 
            base.ProcessArrowKeysForSingleMultipleSelection(args); 
    } 
 
    bool IsCaptionSummaryRow(int rowIndex) 
    { 
        var startIndex = this.DataGrid.TableControl.ResolveStartIndexBasedOnPosition(); 
        var record = this.DataGrid.View.TopLevelGroup.DisplayElements[rowIndex - startIndex]; 
 
        return record != null && record is Group; 
    } 
 
    bool IsGroupSummaryRow(int rowIndex) 
    { 
        var startIndex = this.DataGrid.TableControl.ResolveStartIndexBasedOnPosition(); 
        var record = this.DataGrid.View.TopLevelGroup.DisplayElements[rowIndex - startIndex]; 
 
        return record != null && record is SummaryRecordEntry; 
    } 
 
 
 
    private int GetNextRecordRowIndex(int currentRowIndex) 
    { 
        int nextRecordRowIndex = currentRowIndex + 1; 
 
        if (nextRecordRowIndex > this.GetLastRowIndex(this.DataGrid)) 
            return this.DataGrid.CurrentCell.RowIndex; 
 
        if (!this.IsCaptionSummaryRow(nextRecordRowIndex) && !this.IsGroupSummaryRow(nextRecordRowIndex)) 
            return nextRecordRowIndex; 
        else 
            return GetNextRecordRowIndex(nextRecordRowIndex); 
    } 
 
    private int GetLastRowIndex(SfDataGrid dataGrid) 
    { 
        if (dataGrid.View.Records.Count == 0) 
            return -1; 
        var footerCount = dataGrid.GetUnboundRowsCount(VerticalPosition.Bottom, true); 
        int count = 0; 
        int index = dataGrid.RowCount - (dataGrid.TableControl.GetTableSummaryCount(VerticalPosition.Bottom) + footerCount + 1); 
        for (int start = index; start >= 0; start--) 
        { 
            if (!dataGrid.TableControl.RowHeights.GetHidden(start, out count)) 
                return start; 
        } 
 
        return index; 
    } 
 
    private int GetPreviousRecordRowIndex(int currentRowIndex) 
    { 
        int previousRecordRowIndex = currentRowIndex - 1; 
 
        if (previousRecordRowIndex <= 0) 
            return this.DataGrid.CurrentCell.RowIndex; 
 
        if (!this.IsCaptionSummaryRow(previousRecordRowIndex) && !this.IsGroupSummaryRow(previousRecordRowIndex)) 
            return previousRecordRowIndex; 
        else 
            return GetPreviousRecordRowIndex(previousRecordRowIndex); 
    } 
} 
 


Regards, 
Deivaselvan 



AV Avinash October 16, 2018 04:18 PM UTC

Hi Deivaselva,

Given solution works fine. But i have one more question how to process enter key same as down key


DY Deivaselvan Y Syncfusion Team October 17, 2018 05:27 AM UTC

Hi Avinash, 

Thanks for the update. 

You can process the enter key operation same as the down arrow key by overriding the method HandleKeyOperations in the custom SelectionController. Please refer to the following code example and sample from the given location which illustrate the same. 
 
Code Example:  
 
protected override void HandleKeyOperations(KeyEventArgs args) 
{ 
    if(args.KeyCode == Keys.Enter) 
    { 
        KeyEventArgs arguments = new KeyEventArgs(Keys.Down); 
        base.HandleKeyOperations(arguments); 
        args.Handled = arguments.Handled; 
        return; 
    } 
 
    base.HandleKeyOperations(args); 
} 
 
 
Regards, 
Deivaselvan 



AV Avinash October 20, 2018 04:57 PM UTC

Hi Deivaselva,

Given solution works fine. But i have one more question how to skip selection on click/mouse click  same as up key & down key(ie. CaptionSummaryRow  & GroupSummaryRow should not be selected)


MA Mohanram Anbukkarasu Syncfusion Team October 22, 2018 10:30 AM UTC

Hi Avinash, 

Thanks  for your update. 

You can skip the pointer selection for the summary rows by overriding the HandlePointerOperations method in the custom SelectionController. Please refer to the following code example and sample from the given location. 

Code Example  :  

protected override void HandlePointerOperations(Syncfusion.WinForms.DataGrid.Events.DataGridPointerEventArgs args, RowColumnIndex rowColumnIndex) 
{ 
    if (this.IsCaptionSummaryRow(rowColumnIndex.RowIndex) || this.IsGroupSummaryRow(rowColumnIndex.RowIndex)) 
        return; 
 
    base.HandlePointerOperations(args, rowColumnIndex); 
} 


Regards, 
Mohanram A. 



AV Avinash October 23, 2018 04:23 AM UTC

Hi Mohanram,

Thanks for your update given solution worked for me.


DY Deivaselvan Y Syncfusion Team October 23, 2018 09:48 AM UTC

Hi Avinash,

We are happy to hear that the given solution meets your requirement. Please let us know if you need any further assistance.

Regards,
Deivaselvan 



AV Avinash December 4, 2018 06:50 AM UTC

[1] Is there any way to hide or remove icon from IndentColumn(expand  or collapse icon for groups)
[2] Need IndentColumn for Group which has another group, IndentColumn should not be displayed for group which has not reocrds


DY Deivaselvan Y Syncfusion Team December 4, 2018 12:09 PM UTC

Hi Avinash, 

Thanks for your update. 

Query 
Solution 
Is there any way to hide or remove icon from IndentColumn(expand  or collapse icon for groups) 
Currently we don’t have support to customize the expand/collapse icon in the group caption. We don’t have any immediate plans to implement.   At the planning stage for every release cycle, we review all open features.  We will let you know when this feature is implemented. 
Need IndentColumn for Group which has another group, IndentColumn should not be displayed for group which has not reocrds 
You can achieve this by setting the width of the indent column to 0 by default and change it to 28 only when the SfDataGrid.GroupColumnDescriptions count is greater than 1. Please refer the following code example and sample from the following link. 

Code example :  
void GroupColumnDescriptions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
{ 
    if (this.sfDataGrid.GroupColumnDescriptions.Count > 1) 
        this.sfDataGrid.IndentColumnWidth = 28; 
    else 
        this.sfDataGrid.IndentColumnWidth = 0; 
} 


Please let us know if the given solution doesn’t meet your requirement. 


Regards, 



AV Avinash December 6, 2018 10:37 AM UTC

Given solution for moving through grid is working fine, but when reached at last record, last row of table summary & group summary is displaying & when reached at first record first row of Caption Summary  is not displaying
Kindly provide workaround for the same (i.e. when reached at last record grid should scroll to last & when reached at first record grid should scroll to top)


DY Deivaselvan Y Syncfusion Team December 7, 2018 05:59 AM UTC

Hi Avinash, 

Thanks for your update. 

We can reproduce the reported scenario in our sample. We have modified the sample we have provided to skip selection for the caption summary any group summary row by considering the reported scrolling behavior. Please refer the following modified code example and sample from the given link. 

Code example :  

public Form1() 
{ 
    InitializeComponent(); 
    this.sfDataGrid.SelectionController = new CustomRowSelectionController(this.sfDataGrid); 
} 
 
public class CustomRowSelectionController : RowSelectionController 
{ 
    SfDataGrid DataGrid; 
 
    public CustomRowSelectionController(SfDataGrid sfDataGrid) 
        : base(sfDataGrid) 
    { 
        this.DataGrid = sfDataGrid; 
    } 
 
    protected override void HandlePointerOperations(Syncfusion.WinForms.DataGrid.Events.DataGridPointerEventArgs args, RowColumnIndex rowColumnIndex) 
    { 
        if (this.IsCaptionSummaryRow(rowColumnIndex.RowIndex) || this.IsGroupSummaryRow(rowColumnIndex.RowIndex)) 
            return; 
 
        base.HandlePointerOperations(args, rowColumnIndex); 
    } 
 
    protected override void HandleKeyOperations(KeyEventArgs args) 
    { 
        if (args.KeyCode == Keys.Enter) 
        { 
            KeyEventArgs arguments = new KeyEventArgs(Keys.Down); 
            base.HandleKeyOperations(arguments); 
            args.Handled = arguments.Handled; 
            return; 
        } 
 
        base.HandleKeyOperations(args); 
    } 
 
    protected override void ProcessArrowKeysForSingleMultipleSelection(KeyEventArgs args) 
    { 
        if (args.KeyCode == Keys.Up) 
        { 
            this.DataGrid.MoveToCurrentCell(new RowColumnIndex(this.GetPreviousRecordRowIndex(this.DataGrid.CurrentCell.RowIndex), this.DataGrid.CurrentCell.ColumnIndex)); 
        } 
        else if (args.KeyCode == Keys.Down) 
        { 
            this.DataGrid.MoveToCurrentCell(new RowColumnIndex(this.GetNextRecordRowIndex(this.DataGrid.CurrentCell.RowIndex), this.DataGrid.CurrentCell.ColumnIndex)); 
        } 
        else 
            base.ProcessArrowKeysForSingleMultipleSelection(args); 
    } 
 
    bool IsCaptionSummaryRow(int rowIndex) 
    { 
        var startIndex = this.DataGrid.TableControl.ResolveStartIndexBasedOnPosition(); 
        var record = this.DataGrid.View.TopLevelGroup.DisplayElements[rowIndex - startIndex]; 
 
        return record != null && record is Group; 
    } 
 
    bool IsGroupSummaryRow(int rowIndex) 
    { 
        var startIndex = this.DataGrid.TableControl.ResolveStartIndexBasedOnPosition(); 
        var record = this.DataGrid.View.TopLevelGroup.DisplayElements[rowIndex - startIndex]; 
 
        return record != null && record is SummaryRecordEntry; 
    } 
 
 
 
    private int GetNextRecordRowIndex(int currentRowIndex) 
    { 
        int nextRecordRowIndex = currentRowIndex + 1; 
 
        if (nextRecordRowIndex > this.GetLastRowIndex(this.DataGrid)) 
        { 
            this.DataGrid.TableControl.VerticalScroll.Value = this.DataGrid.TableControl.VerticalScroll.Maximum; 
            return this.DataGrid.CurrentCell.RowIndex; 
        } 
 
        if (!this.IsCaptionSummaryRow(nextRecordRowIndex) && !this.IsGroupSummaryRow(nextRecordRowIndex)) 
            return nextRecordRowIndex; 
        else 
            return GetNextRecordRowIndex(nextRecordRowIndex); 
    } 
 
    private int GetLastRowIndex(SfDataGrid dataGrid) 
    { 
        if (dataGrid.View.Records.Count == 0) 
            return -1; 
        var footerCount = dataGrid.GetUnboundRowsCount(VerticalPosition.Bottom, true); 
        int count = 0; 
        int index = dataGrid.RowCount - (dataGrid.TableControl.GetTableSummaryCount(VerticalPosition.Bottom) + footerCount + 1); 
        for (int start = index; start >= 0; start--) 
        { 
            if (!dataGrid.TableControl.RowHeights.GetHidden(start, out count)) 
                return start; 
        } 
 
        return index; 
    } 
 
    private int GetPreviousRecordRowIndex(int currentRowIndex) 
    { 
        int previousRecordRowIndex = currentRowIndex - 1; 
 
        if (previousRecordRowIndex <= 0) 
        { 
            this.DataGrid.TableControl.VerticalScroll.Value = this.DataGrid.TableControl.VerticalScroll.Minimum; 
            return this.DataGrid.CurrentCell.RowIndex; 
        } 
 
        if (!this.IsCaptionSummaryRow(previousRecordRowIndex) && !this.IsGroupSummaryRow(previousRecordRowIndex)) 
            return previousRecordRowIndex; 
        else 
            return GetPreviousRecordRowIndex(previousRecordRowIndex); 
    } 
} 


Regards, 
Deivaselvan 


Loader.
Up arrow icon