Sort Levels by Elevation

Sort Levels by Elevation

vanlion
Advocate Advocate
749 Views
3 Replies
Message 1 of 4

Sort Levels by Elevation

vanlion
Advocate
Advocate

Hello,

 

I customizing the LevelsProperty Sample so it is ordering the levels by Elevation. I already added the following line so everytime you open up the editor the levels are sorted by height

 

List<Level> levelsCollection = collector.OfClass(typeof(Level)).OfType<Level>().OrderBy(lev => lev.Elevation).ToList();

But i know it should also be possible to automatically update the datagridview when the editor is open. But i can't get it to work. any ideas? Thanks!

 

bindingSource1.Sort = "Elevation ASC";

Level property.JPG

0 Likes
Accepted solutions (1)
750 Views
3 Replies
Replies (3)
Message 2 of 4

BIM.Frankliang
Collaborator
Collaborator

Hi Vanlion,

 

     I think that you can try to use WPF MVVM to bind level name and level elevation to DataGrid.

 <DataGrid  
           CanUserAddRows="False"
           CanUserDeleteRows="False"
           Margin="0,10"
           SelectionMode="Single"
           AutoGenerateColumns="False"
           CanUserReorderColumns="False"
           CanUserSortColumns="False"
           AlternatingRowBackground="#EBEBEB"
           Background="white"
           ItemsSource="{Binding ElevationList}">

           <DataGrid.Columns>
                <DataGridTextColumn Width="*" IsReadOnly="True" Header="ElevationName" Binding="{Binding ElevationName}" FontSize="12"/>
                <DataGridTextColumn Width="*" IsReadOnly="True" Header="ElevationValue" Binding="{Binding Elevation}" FontSize="12"/>
<DataGrid.Columns/>
</DataGrid>

 

You could create a class called ElevationModel which contains two properties: ElevationName, ElevationValue

Then, in ViewModel.cs, you could use ObsevableCollection<ElevationModel> ElevationList  binding with DataGrid.

Wish it is helpful for you 🙂

 

Best regards,

Frank Liang

名片2.png

 

 

0 Likes
Message 3 of 4

vanlion
Advocate
Advocate

Hi Frank,

 

Thanks for taking time to help. I'm just starting with Revit and C#. So your example is a little bit difficult for me.

 

I hoped it was simple. Searched a lot in the internet but when you are new to C# it's hard to follow sometimes 😉

0 Likes
Message 4 of 4

vanlion
Advocate
Advocate
Accepted solution
I solved this one!

When implementing the sortableBindinList class and use that to list the levels it's working very well.

Didn't know it was that easy!
0 Likes