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 04:55 PM UTC

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 05:54 PM UTC

Of course, thank you very much!



VS Vijayarasan Sivanandham Syncfusion Team October 21, 2022 04:36 PM UTC

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 06:15 AM UTC

Of course, no problem. Thank you for help!



VS Vijayarasan Sivanandham Syncfusion Team October 27, 2022 04:22 PM UTC

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 08:51 PM UTC

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 09:17 PM UTC

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 02:52 PM UTC

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 06:06 PM UTC

Thank you very much, its works well!

Have a nice day!



VD Vasanthkumar Durairaj Syncfusion Team November 7, 2022 02:15 PM UTC

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