This is a migrated thread and some comments may be shown as answers.

Sorting with custom controls inside grid

5 Answers 61 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michal
Top achievements
Rank 1
Michal asked on 15 Nov 2011, 07:29 AM
Hi,

I have a problem where when I sort the grid (by clicking on the column header) it will sort the items but not the custom controls inside it.

I have a custom textbox inside a grid
<telerik:GridViewDataColumn Header="Notes" Width="*" IsSortable="True" SortMemberPath="Notes" >
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <Controls:CmsTextBox Text="{Binding Notes, Mode=TwoWay}" Height="23"/>
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>

The CmsTextBox got and TextChanged event hooked up that will change the background colour of the textbox to blue if the value has changed.

This all works fine until I start sorting. Sorting works fine but it will not move the changed CmsTextBox with it. Looks like the grid is not moving the physical controls when sorting as the values do sort but control stay at the same position.

Example: Have 5 rows 1 to 5. Each row got one column with text box, they have values 1 to 5. If I change the value in row 4 to 4.5 this textbox will go blue. Then if I sort descending the sort will work fine but the blue textbox has not moved eg will still be on the row 4 instead of row 2.

Please see the attachment picture for illustration.

Thanx
Mike




5 Answers, 1 is accepted

Sort by
0
Michal
Top achievements
Rank 1
answered on 21 Nov 2011, 03:29 AM
Any help?

need more details?
0
Vlad
Telerik team
answered on 21 Nov 2011, 08:03 AM
Hi,

 Sorting is handled on data level. Not on UI!

All the best,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Michal
Top achievements
Rank 1
answered on 21 Nov 2011, 08:33 AM
Cheers,

I though that's is the case, it's definitely behaves that way.

Anyway is there something that I can do to get it sorted on UI side?

Other solution is to make the changes to text box (background of text box turns to blue when there was a change) on the data layer. Unfortunately doing it on the UI is much simpler as I can do it in my custom text box control and all text boxes in my project will automatically get this. Where on data layer I will have to do it manually on every single view model class :)

Mike

0
Vlad
Telerik team
answered on 21 Nov 2011, 08:43 AM
Hi,

 You can use IValueConverter to colorize your TextBox depending on the data. Please check this article for more info:
http://msdn.microsoft.com/en-us/library/cc278072(v=vs.95).aspx

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Michal
Top achievements
Rank 1
answered on 21 Nov 2011, 08:50 AM
Thanx Vlad,

Using IValueConverter  I will have to manually do this on every single text box (I have a lot of them) where on UI I just do it once (as all the text boxes are using my custom text box).

I wanted to avoid doing that :) Looks like I have no other options.

Thanx for your help.

Mike
Tags
GridView
Asked by
Michal
Top achievements
Rank 1
Answers by
Michal
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or