❔ ✅ DataGrid RowStyle depends of the datatype WPF
Hello, how can i change the row style of my datagrid depends of the datatype in it to represent this kind of table.
14 Replies
Are you grouping the data here or can those separators be set anywhere?
theses datas are in a list of step which containts 2 datatype herited from
Step
Step
=> StepNormal
and StepSpecial
so the so called separators in blue and yellow if i've understand can be set anywhere
depends of his index called Pas
in our caseNot really sure if there is an elegant solution for this, but have the following in mind:
maybe i can use listview or combobox ? idk i'm not really familiar with wpf
- bind the list of steps and the indices to your datagrid view as a multibinding
- create a class that contains only the data and a bool
IsSeparator
- create a converter that converts the list of items and the indices to a new list of that new class
- create a data template for ??? that can handle IsSeparator
and shows what you need
not really sure which template you have to modify, hence the ???
just be DataGrid.ItemTemplate
I'm not sure to fully understand your explanation.
i've not mention but the separator is link to the datatype, you put the separator if the step is
StepSpecial
.
I had something in mind like when the datatype is Stepnormal
i set the rowstyle to get the number and if the datatype is StepSpecial
, i just set the row style to have a yellow of blue style background with the image
currently i've something like this
Ah, so then we can skip the converter part
But you'll need different data templates then
i create a template to each step and i select the good one with a converter ?
Hold on, I'm gonna check something really quick
So I'm quite sure you need to use
DataTemplateSelector
here. But i'm not sure how it is exactly assigned to a gridview
I made a simple test case, however the selector never tries to choose a template seems to work for a ListBox thoughi should probably use
itemTemplateselector
for the datagrid i think
can you enlighten me please what make me choose between listbox or datagrid in that case ?DataGrid is for editing
ListBox is not
It seems to work for a ListBox thoughSeems like you'd need to assign a
CellTemplateSelector
directly on a DataGridTemplateColumn
itself, instead of the ItemTemplate
on the DataGrid
So here's a selector class I made for the test case. Note that I used IUser
as the base and User
, User2
as the deriving types
And this is how you add it as a resourceok we are close to the solution,
Selector
is definitly the right way to resolve my problem
from there i think i can continu you gave me all the key to do it Tanks a lot ! 🙂Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.