D
D
doroshchenkov2021-12-20 18:22:08
.NET
doroshchenkov, 2021-12-20 18:22:08

How to override .ToString() for a collection in DataGrid WPF?

Hello. WPF. Faced such a problem. I want the datagrid to display the contents of the collection separated by commas instead of "(Collection)".
61c09d1bad9be256014912.png
I tried to make my own class inherited from a regular sheet and overridden .ToList() in it. Then I passed this collection to the datagrid and still - "(Collection)"

public class OrderStringCollection<Orderstring> : List<Orderstring>
    {
        public override string ToString()
        {
            return string.Join(", ", this);
        }
    }

Does anyone have any suggestions on how this can be implemented?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JeremiSharkboy, 2021-12-21
@JeremiSharkboy

In xaml, use the converter for the field. Like {Binding Orders, Converter={staticres converter}} and in the converter just go through the data you need and create the desired string

R
Roman, 2021-12-21
@yarosroman

You can create a property on a sheet that gives you the desired string, and bind to it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question