Click here to Skip to main content
Click here to Skip to main content

DataGrid Visual Column Separator

, 6 Aug 2013
Rate this:
Please Sign up or sign in to vote.
DataGrid column separator

Introduction

I had to visually separate my DataGrid in two different parts. I used XAML to do so and added a small unused column. I searched for a solution but I didn't find anything that would solve my problem.

Using the Code

It is very simple, all in XAML. You just need to add a column and change the Header and Cell style.

<DataGridTemplateColumn MinWidth="4" MaxWidth="4" 
IsReadOnly="True" CanUserResize="False">
    <DataGridTemplateColumn.HeaderStyle>
        <Style TargetType="{x:Type DataGridColumnHeader}">
            <Setter Property="Margin" Value="-1" />
            <Setter Property="Background" Value="Black" />
            <Setter Property="BorderBrush" Value="Black" />
            <Setter Property="BorderThickness" Value="2" />
        </Style>
    </DataGridTemplateColumn.HeaderStyle>
    <DataGridTemplateColumn.CellStyle>
        <Style TargetType="{x:Type DataGridCell}">                       
            <Setter Property="BorderBrush" Value="Black" />
            <Setter Property="BorderThickness" Value="2" />                          
            <Setter Property="Focusable" Value="False" />
        </Style>
    </DataGridTemplateColumn.CellStyle>
</DataGridTemplateColumn> 

With this separator, you can't use arrow to go between the two parts of the DataGrid but with Tab it is alright.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ced743
Software Developer
Switzerland Switzerland
After graduating I started working as a Software Developer for a timing and scoring company.

Comments and Discussions

 
SuggestionPicture would be nice? PinmemberSilvabolt31-Jul-13 9:02 
QuestionThis isn't ASP.NET... Pinmemberrbegley131-Jul-13 4:03 
AnswerRe: This isn't ASP.NET... PinprofessionalCed7435-Aug-13 22:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 6 Aug 2013
Article Copyright 2013 by Ced743
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid