How to check/uncheck GridSwitchColumn programmatically in C# and how to get value of it.

Sir/Madam,

How to check/uncheck GridSwitchColumn programmatically in C# and how to get value of it.


Thanking you


1 Reply

SV Suja Venkatesan Syncfusion Team September 6, 2022 02:13 PM UTC

Hi Amish,

We would like to let you know that you can get and set the value of GridSwitchColumn when the rowindex and columnindex are known values, then using reflection you can get and set the value of the cell like the below code snippet.

Code Snippet:
void Button_Clicked(System.Object sender, System.EventArgs e)
        {
            var dataRow = this.sfGrid.GetRowGenerator().Items.FirstOrDefault(x => x.RowIndex == 2);
            var visiblecolumns = dataRow.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name.Equals("VisibleColumns")).GetValue(dataRow) as List<DataColumnBase>;

            var name = visiblecolumns.FirstOrDefault(x => x.ColumnIndex == 0).GridColumn.MappingName;
            //Get Value
            bool val = (bool)dataRow.RowData.GetType().GetProperty(name).GetValue(dataRow.RowData);
            if((val)==true)
            {
                //Set Value
                dataRow.RowData.GetType().GetProperty(name).SetValue(dataRow.RowData, false);
            }
            else
                dataRow.RowData.GetType().GetProperty(name).SetValue(dataRow.RowData, true);
        }

We have attached a sample for your reference, you can customize the sample as per your wish. If we misunderstood your requirement, please revert to us with more details about your requirement with an illustration video or image. it will be more helpful for us to provide timely solutions.

Regards,
Suja.

Attachment: GettingStarted_10_708f6938.zip

Loader.
Up arrow icon