views:

73

answers:

1

I haven't been able to find anyway to dynamically add a border around a column in a silverlight datagrid. Here is my xaml of my datagrid:

<sdk:DataGrid x:Name="PlannedAndBookedMonthlyTable" ItemsSource="{Binding}" AutoGenerateColumns="False" Margin="5,0,5,5">
   <sdk:DataGrid.Columns>
      <sdk:DataGridTextColumn x:Name="MonthlyHeaderName" Header="" Binding="{Binding SeriesName}" />
      <sdk:DataGridTextColumn x:Name="MonthlyHeaderJan" Header="Jan" Binding="{Binding JanValue}" />
      <sdk:DataGridTextColumn x:Name="MonthlyHeaderFeb" Header="Feb" Binding="{Binding FebValue}" />
      <sdk:DataGridTextColumn x:Name="MonthlyHeaderMar" Header="Mar" Binding="{Binding MarValue}" />
      <sdk:DataGridTextColumn x:Name="MonthlyHeaderApr" Header="Apr" Binding="{Binding AprValue}" />
      <sdk:DataGridTextColumn x:Name="MonthlyHeaderMay" Header="May" Binding="{Binding MayValue}" />
      <sdk:DataGridTextColumn x:Name="MonthlyHeaderJun" Header="Jun" Binding="{Binding JunValue}" />
      <sdk:DataGridTextColumn x:Name="MonthlyHeaderJul" Header="Jul" Binding="{Binding JulValue}" />
      <sdk:DataGridTextColumn x:Name="MonthlyHeaderAug" Header="Aug" Binding="{Binding AugValue}" />
      <sdk:DataGridTextColumn x:Name="MonthlyHeaderSep" Header="Sep" Binding="{Binding SepValue}" />
      <sdk:DataGridTextColumn x:Name="MonthlyHeaderOct" Header="Oct" Binding="{Binding OctValue}" />
      <sdk:DataGridTextColumn x:Name="MonthlyHeaderNov" Header="Nov" Binding="{Binding NovValue}" />
      <sdk:DataGridTextColumn x:Name="MonthlyHeaderDec" Header="Dec" Binding="{Binding DecValue}" />
      <sdk:DataGridTextColumn x:Name="MonthlyHeaderTotal" Header="Total" Binding="{Binding Total}" />
   </sdk:DataGrid.Columns>
</sdk:DataGrid>

This is the effect that I want to accomplish:

alt text

How do I set the border on a column of data that depends on what current calendar month it is?

+1  A: 

Each row in a DataGrid is a template, as is each cell. The normal DataGrid has no concept of cells and current cell positions, just selected rows.

If you were able to get enough positional information I would say you could overlay a border over the DataGrid, but the debugger shows me there is not enough information available in a DataGrid to even calculate the position of the current selected cell.

One possible option

The only way I can think of doing this with a DataGrid is catching focus events on the individual cell controls (e.g. TextBoxes in the DataGrid) and use the position of the selected control relative to the parent to work out the border position. Each column will need to be a templated column so that you can hook up the GotFocus events.

Otherwise...

...you will need to try a different sort of control to get the result you are seeking.

You could use a plain old Grid, e.g. full of TextBox controls, but you will need to handle selection and keyboard navigation of the grid yourself.

If budget permits, I would look around for a 3rd party spreadsheet control for Silverlight. Otherwise see if anyone has built one on Codeplex or elsewhere.

Enough already
I had to go the route of using a plain old Grid to achieve the desired look. Thanks for the input.
amurra