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

Multiple cell renderer based on condition

Hello,

It is possible to use multiple cell renderer in the same column in SfDataGrid?

So when the cell value is not null -> I should use Textbox cell renderer with string value.

When the cell value is null -> I should use a Button cell and handle the click event. 

After I click on button can I switch to Textbox cell from Button cell in realtime without refresh?


Thank you!

BR, SZL


10 Replies 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team October 19, 2022 11:55 AM

Hi SZL,

Currently, we are analyzing your requirement for a “Multiple cell renderer based on condition in SfDataGrid”. So, we need two more business days to validate this. We will update you with further details on October 21, 2022.


We appreciate your patience until then.


Regards,

Vijayarasan S



SZ SZL October 19, 2022 12:54 PM

Of course, thank you very much!



VS Vijayarasan Sivanandham Syncfusion Team October 21, 2022 11:36 AM

Hi SZL,

We deeply regret the delay and inconvenience caused.


We are still working on this. So, we need two more business days to validate this. We will update you with further details on October 27, 2022.


We appreciate your patience and understanding.

Regards,
Vijayarasan S



SZ SZL replied to Vijayarasan Sivanandham October 24, 2022 01:15 AM

Of course, no problem. Thank you for help!



VS Vijayarasan Sivanandham Syncfusion Team October 27, 2022 11:22 AM

Hi SZL,


We deeply regret the delay and inconvenience caused.


We are still working on this. So, we need two more business days to validate this. We will update you with further details on October 31, 2022.


We appreciate your patience and understanding.


Regards,

Vijayarasan S



VS Vijayarasan Sivanandham Syncfusion Team October 31, 2022 03:51 PM

Your requirement to create multiple cells (ex: Button, Textbox ) based on conditions in SfDataGrid can be achieved by creating a custom column. Find the sample demo in the attachment.

UG Link: https://help.syncfusion.com/windowsforms/datagrid/columntypes#creating-new-column-and-renderer

KB Link: https://www.syncfusion.com/kb/11754/how-to-add-the-button-and-text-in-gridtextcolumn-in-winforms-datagrid-sfdatagrid

https://www.syncfusion.com/kb/11573/how-to-add-the-radiobutton-column-in-winforms-datagrid-sfdatagrid


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: Sample_27a82d1b.zip


SZ SZL replied to Vijayarasan Sivanandham November 2, 2022 04:17 PM

Hello,

Thank you very much for help and for the sample! Its very cool!

I have two little question about your solution:

I try set the cell value after button click with the following extended lines:




This works perfect, but I should update the above code without know the model type (OrderInfo). 

I would like make a general solution where the model can be anything.

So my question is, how can I update the cell value after button click, without know the model type?


Can you confirm please, that your solution works well with advanced grid functions too? (for example Filtering, Grouping, Sorting etc. in all cases?)


Thank you very much!




VS Vijayarasan Sivanandham Syncfusion Team November 3, 2022 09:52 AM

Find the responses to your queries below.

Queries

Responses

 

This works perfect, but I should update the above code without know the model type (OrderInfo).

I would like make a general solution where the model can be anything.

So my question is, how can I update the cell value after button click, without know the model type? 

 

Your requirement to update the cell value after a button click, without knowing the model type in SfDataGrid can be achieved by using View.GetPropertyAccessProvider.GetValue method in SfDatGrid. Refer to the below code snippet,

protected override void OnMouseDown(DataColumnBase dataColumn, RowColumnIndex rowColumnIndex, MouseEventArgs e)

{

if (e.Location.X > rect.X && e.Location.X < (rect.X + rect.Width))

{

    isButtonClicked = true;

 

    //Here update the cell value

    if (DataGrid.View != null && dataColumn != null && dataColumn.GridColumn != null && DataGrid.TableControl != null)

    {

 

        var recordIndex = DataGrid.TableControl.ResolveToRecordIndex(rowColumnIndex.RowIndex);

 

        if (recordIndex < 0)

            return;

 

        object record = null;

 

        if (DataGrid.View.TopLevelGroup != null)

        {

            var displayElement = DataGrid.View.TopLevelGroup.DisplayElements[recordIndex];

 

            if (displayElement == null)

                return;

            if (displayElement is RecordEntry)

                record = ((RecordEntry)displayElement).Data;

        }

        else 

            record = DataGrid.View.Records[recordIndex].Data;

 

        //set the value for particular cell in the record

        if (record != null)

            DataGrid.View.GetPropertyAccessProvider().SetValue(record, dataColumn.GridColumn.MappingName, "5");

    }

 

    //Here customize the button click based on your scenario

    MessageBox.Show("Button Clicked");

}

}

 

Can you confirm please, that your solution works well with advanced grid functions too? (for example Filtering, Grouping, Sorting etc. in all cases?)

 

Yes. The custom column performs data operations (ex: Filtering, Grouping, Sorting) based on underlined data.


Find the sample in the attachment.


Attachment: Sample_785120fc.zip

Marked as answer

SZ SZL replied to Vijayarasan Sivanandham November 3, 2022 01:06 PM

Thank you very much, its works well!

Have a nice day!



VD Vasanthkumar Durairaj Syncfusion Team November 7, 2022 09:15 AM

We are glad that the reported issue was resolved on your side. Please let us know if you need any other details on this. As always, we will be happy to assist you.


Loader.
Live Chat Icon For mobile
Up arrow icon