Disallow columns from appearing on the Datagrid

Jun 4, 2009 at 6:43 AM

I originally posted this question in the MSDN WPF forums but since my questions were specific to the WPF Datagrid I thought I'd repost it here.  Any help would be highly appreciated.

I have a couple of question related to the WPF datagrid found here: http://wpf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25047

1) I use this datagrid in one of my applications and I use its ItemSource property to bind it to a collection.  The datagrid properly displays all properties exposed by the object represented by the collection.  However, is there a way to prevent the datagrid from displaying certain properties as columns?  For example, I use a marker property to determine if I need to highlight a particular row but the datagrid ends up displaying that property too as a column.  How can I avoid this?

2) Is there a way I can push up a few rows to the very top of the datagrid?  I have implemented a Find functionality which might take a partial input and highlights any row whose primary key matches the partial input.  Initially I thought I'd simply highlight the relevant items (which is why I use that marker property I mentioned in the previous point).  The only problem happens when some rows are not in the visible area of the datagrid.  If they are somewhere way down, obviously the user will have to scroll down and see the hits.  Therefore I was wondering if I could retrieve all the matching rows and move them to the top of the datagrid.  Is this possible?

Jun 4, 2009 at 7:07 AM

1) There is an event that fires on each auto-generated column - AutoGeneratingColumn or something along the lines of that. You may want to look into it. Alternatively, you could disable automatic column generation and define the columns in either XAML or code-behind yourself.

2) You could sort based on your marker property first, and whatever the user wants second. Just insert it at the top of the sort order list when the sorting is changed. It won't exactly "move" the rows but it will have the same effect from the user's point of view.