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
close icon

Select Rows Based on Cell Value within that row

I have a datagrid populated with information. I want to create a button that will select all rows that contain a text cell with the phrase "Bulk." How do I accomplish this?

1 Reply

AS Ayyanar Sasi Kumar Jeyaraj Syncfusion Team January 7, 2016 12:09 PM UTC

Hi Alex,

Thanks for contacting Syncfusion support.

You can achieve your requirement by GetPropertyAccessProvider.By using this you can get the value of the record data and the mapping name of the datagrid. When the record data is equal to the given phrase value, the row will be selected.
Please refer the below code snippet
C#

private void datagrid_ItemsSourceChanged(object sender, GridItemsSourceChangedEventArgs e)

        {

            if (datagrid.View != null)

                reflector = datagrid.View.GetPropertyAccessProvider();

            else

                reflector = null;

        }




private void Button_Click(object sender, RoutedEventArgs e)

        {

            var totalRowIndex = datagrid.View.Records.Count;

            var totalColumnIndex = datagrid.Columns.Count; 

            for (int recordIndex = 0; recordIndex < totalRowIndex; recordIndex++)

            {

                for (int columnindex = 0; colindex < totalColumnIndex; columnindex++)

                {

                    var record = this.datagrid.View.Records[recordIndex];

                    var mappingName = datagrid.Columns[columnindex].MappingName;

                    var currentCellValue = reflector.GetValue(record.Data, mappingName);

                    if (currentCellValue.ToString()== "Bulk")

                    {

                        object item = datagrid.View.Records[recordIndex];

                        datagrid.SelectedItems.Add(item);

                    }

                }

            }
        }


Sample Location: http://www.syncfusion.com/downloads/support/forum/121605/ze/WPF1885539734


Please let us know if you have any further assistance.

Regards
Ayyanar

Loader.
Live Chat Icon For mobile
Up arrow icon