Title bar on DataGrid in WPF

T

tshad

I am doing a simple datagrid that is autogenerated and it works fine except
the column titles are scewed.

This seems to be because there is a little rectangle with a down arrow that
is about an inch and a half wide that causes all the other columns pushed to
the right and not over the correct columns.

In my xaml, I have:

<WrapPanel Grid.Row="4">
<my:DataGrid Height="200" Name="grdData" Width="469"
ItemsSource="{Binding}" />
</WrapPanel>

And my c# code is:

private void CollectionSample()
{
ProductManager mgr = new ProductManager();
try
{
grdData.ItemsSource = mgr.BuildCollection();
}
catch (Exception exc)
{
}
}

Where the mgr.BuildCollection() returns a collection.

It displays fine except for the column headers.

Thanks,

Tom
 
T

tshad

Angel J. Hernández M. said:
Hi there,

I don't really understand your issue but, if you want to set the "column
title" you must then modify/deal with the column you're interested on
through the Columns collection, for instance:

grdBlocks.Columns[0].Header = "Test";

The problem isn't setting the heading, the problem when you allow the
datagrid to autogenerate the columns:

<WrapPanel Grid.Row="4">
<my:DataGrid Height="200" Name="grdData" Width="469"
AutoGenerateColumns="True"
ItemsSource="{Binding}" />
</WrapPanel>

In the Designer, you can see this column in the titlebar that is about an
inch wide with a little triangle at the left. It then has a long title bar
taking up the rest of the row.

When you run the program that same header is there (same size) and when you
press it, it selects everything in the grid. But the 1st column (after the
titlebar) is only about 1/16 of an inch wide and you apparently use this to
select the row. Since this Select All button is way longer that the 1st
column, the second header (ProductID for instance) starts almost to the end
of the ProductID column and all the other column headers (which are there)
are also off by the same amount.

I can't seem to define the columns, as I mentioned in my other post, because
the program keeps freezing (actually seems to be in an infinite loop).

So the DG is really useless to me until they fix it.

Thanks,

Tom
 
T

tshad

Found out how to solve the problem.

Add HeaderVisibility="Column" to the Datagrid.

Tom
tshad said:
Angel J. Hernández M. said:
Hi there,

I don't really understand your issue but, if you want to set the "column
title" you must then modify/deal with the column you're interested on
through the Columns collection, for instance:

grdBlocks.Columns[0].Header = "Test";

The problem isn't setting the heading, the problem when you allow the
datagrid to autogenerate the columns:

<WrapPanel Grid.Row="4">
<my:DataGrid Height="200" Name="grdData" Width="469"
AutoGenerateColumns="True"
ItemsSource="{Binding}" />
</WrapPanel>

In the Designer, you can see this column in the titlebar that is about an
inch wide with a little triangle at the left. It then has a long title
bar taking up the rest of the row.

When you run the program that same header is there (same size) and when
you press it, it selects everything in the grid. But the 1st column
(after the titlebar) is only about 1/16 of an inch wide and you apparently
use this to select the row. Since this Select All button is way longer
that the 1st column, the second header (ProductID for instance) starts
almost to the end of the ProductID column and all the other column headers
(which are there) are also off by the same amount.

I can't seem to define the columns, as I mentioned in my other post,
because the program keeps freezing (actually seems to be in an infinite
loop).

So the DG is really useless to me until they fix it.

Thanks,

Tom
Regards,

--
Angel J. Hernández M
MCP,MCAD,MCSD,MCDBA
Microsoft MVP
http://www.ajhsis.com
http://msmvps.com/blogs/angelhernandez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top