How can i get selectedrow's rowtype ?

Hi
How can i get selectedrow's rowtype ?

3 Replies

AA Arulraj A Syncfusion Team August 15, 2018 12:32 PM UTC

Hi Eren, 

Thanks for using Syncfusion products. 

There is no default API which gives the SelectedRow’s RowType. However, the selected rows are maintained in SfDataGrid.SelectedItems and SfDataGrid.SelectedNodeEntries. All the default rows selections are maintained in the SelectedItems and other than default row selections are maintained in SelectedNodeEntries. Please make use of the following code. 

Code Example: 
if (sfDataGrid1.SelectedItems.Count > 0) 
{ 
    // All the default rows will be added to SelectedItems. 
    var selectedItem = sfDataGrid1.SelectedItems.LastOrDefault(); 
} 
 
if (sfDataGrid1.SelectedNodeEntries.Count > 0) 
{ 
    // Other than default row. 
    var selectedRowInfo = sfDataGrid1.SelectedNodeEntries.LastOrDefault(); 
    var isAddNewRowType = selectedRowInfo.IsAddNewRow; 
    var isFilterRowType = selectedRowInfo.IsFilterRow; 
    var isCaptionRowType = selectedRowInfo.IsCaptionRow; 
    var isGroupSummaryRowType = selectedRowInfo.IsGroupSummaryRow; 
    var isunboundRowType = selectedRowInfo.IsUnboundRow; 
} 
 
Sample Location: 

Arulraj A 



ER Eren August 15, 2018 05:21 PM UTC

Thank you but this solution can't help me. Do you have a chance to add this property as the default API in the next update ? one more question can I cast the selecteditem to datarowbase





AA Arulraj A Syncfusion Team August 16, 2018 01:17 PM UTC

Hi Eren, 

Thanks for your update. 

Do you have a chance to add this property as the default API in the next update? 
Currently we don’t have plan to introduce a property to specify the RowType of the selected rows.  

Since the selected rows are maintained separately for the SelectedItems (for DefaultRow) and SelectedNodeEntries (for row type other than DefaultRow).  

If you want to get the row type from the SelectedItems or SelectedNoteEntries collection, you can use the  following helper method, 

Code Sample: 
public RowType GetRowType(object row) 
{ 
    if(this.sfDataGrid.SelectedItems.Contains(row)) 
        return RowType.DefaultRow; 
     
    if(this.sfDataGrid.SelectedNodeEntries.Contains(row)) 
    { 
        var selectedRowInfo = this.sfDataGrid.SelectedNodeEntries.FirstOrDefault(x => x == row); 
        if (selectedRowInfo != null) 
        { 
            if (selectedRowInfo.IsFilterRow) 
                return RowType.FilterRow; 
            if (selectedRowInfo.IsAddNewRow) 
                return RowType.AddNewRow; 
            if (selectedRowInfo.IsCaptionRow) 
                return RowType.CaptionRow; 
            if (selectedRowInfo.IsGroupSummaryRow) 
                return RowType.SummaryRow; 
        } 
    } 
 
    return RowType.DefaultRow; 
} 
 
 
private void button1_Click(object sender, EventArgs e) 
{ 
    if (sfDataGrid.SelectedNodeEntries.Count > 0) 
        Console.WriteLine(GetRowType(sfDataGrid.SelectedNodeEntries[0])); 
 
    if (sfDataGrid.SelectedItems.Count > 0) 
        Console.WriteLine(GetRowType(sfDataGrid.SelectedItems[0])); 
} 
 
can I cast the selecteditem to datarowbase 
Since the SelectedItem is the business object of the data row,  it cannot be converted to the  DataRowBase.  

Arulraj A 


Loader.
Up arrow icon