We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Count/get selected rows in detail view

Hello,

How to get number of selected rows and and value from specific columns from selected rows when I have multiple selected rows in child grid but outside ChildGrid_SelectionChanged(), for example on Button click.

So far I have this:

SfDataGrid childGrid = new SfDataGrid();

 public From1()
        {
            InitializeComponent();
            childGrid.SelectionChanged += ChildGrid_SelectionChanged;
           
            InitGrid();
        }

 private void ChildGrid_SelectionChanged(object sender, Syncfusion.WinForms.DataGrid.Events.SelectionChangedEventArgs e)
        {
          
         
        }

 private void InitGrid()
        {              

            GridViewDefinition orderDetailsView = new GridViewDefinition();
            orderDetailsView.RelationalColumn = "IzdatnicaStavke";        
            childGrid.QueryRowStyle += ChildGrid_QueryRowStyle;         
            childGrid.Style.HeaderStyle.BackColor = Color.Yellow;
            childGrid.AutoGenerateColumns = false;
            childGrid.RowHeight = 21;
            childGrid.SelectionMode = GridSelectionMode.Extended;
            childGrid.SelectionUnit = SelectionUnit.Row;
            NumberFormatInfo nfi = new NumberFormatInfo();
            nfi.NumberDecimalDigits = 2;
            nfi.NumberGroupSizes = new int[] { };
            childGrid.Columns.Add(new GridTextColumn() { MappingName = "IDIzdatnica", HeaderText = "ID", Visible = false });
            childGrid.Columns.Add(new GridTextColumn() { MappingName = "SifraRD", HeaderText = "Šifra rd." });
            childGrid.Columns.Add(new GridTextColumn() { MappingName = "OpisArtikla", HeaderText = "Opis/naziv" });
            childGrid.Columns.Add(new GridTextColumn() { MappingName = "NazivGrupe", HeaderText = "Grupa" });
            childGrid.Columns.Add(new GridTextColumn() { MappingName = "JedMjera", HeaderText = "Jed. mj." });                     
            childGrid.Columns.Add(new GridNumericColumn() { MappingName = "Kolicina", HeaderText = "Količina", NumberFormatInfo = nfi });           
            childGrid.Columns.Add(new GridTextColumn() { MappingName = "Napomena", HeaderText = "Napomena" });
         
            orderDetailsView.DataGrid = childGrid;
            this.gridIzdatnica.DetailsViewDefinitions.Add(orderDetailsView);
            this.gridIzdatnica.HideEmptyGridViewDefinition = true;

        }

Problem is that whatever I do the number of selected items are always 0 in childGrid.

3 Replies

GG Gowtham Gopalsamy Syncfusion Team October 22, 2019 12:32 PM UTC

Hi Josip,  
    
Thank you for using Syncfusion controls.   
   
You can achieve your requirement “to get the selected items count for DetailsViewDataGrid” by using SfDataGrid.SelectedDetailsViewGrid.SelectedItems property.    
   
Please find the below code snippet.  
   
var count = this.sfDataGrid1.SelectedDetailsViewGrid.SelectedItems.Count;   
   
Please find the below sample link.  
    
   
Please let us know, if you require further assistance on this.   
    
Regards,   
Gowtham.   
 



JO Josip replied to Gowtham Gopalsamy October 22, 2019 04:59 PM UTC

Hi Josip,  
    
Thank you for using Syncfusion controls.   
   
You can achieve your requirement “to get the selected items count for DetailsViewDataGrid” by using SfDataGrid.SelectedDetailsViewGrid.SelectedItems property.    
   
Please find the below code snippet.  
   
var count = this.sfDataGrid1.SelectedDetailsViewGrid.SelectedItems.Count;   
   
Please find the below sample link.  
    
   
Please let us know, if you require further assistance on this.   
    
Regards,   
Gowtham.   
 


Thank you very much!


FP Farjana Parveen Ayubb Syncfusion Team October 23, 2019 10:52 AM UTC

Hi Josip 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 
 
Regards, 
Farjana Parveen A 


Loader.
Live Chat Icon For mobile
Up arrow icon