Sudh
Sudh

Reputation: 1335

Strange Issues with datagrid in wpf

I am new to wpf and working on an accounting application. My problem is so simple yet I am astonished that I can not find a simplistic solution for this, it goes like this:

I have to create a datagrid in which only columns should have visible borders.

I mean it should look something like this:

 ____________________
 | col1 | col2| col3|
 |______|_____|_____|
 |   r1 |  r1 |  r1 |
 |   r3 |  r2 |  r2 |
 |      |     |     |
 |      |     |     |
 |      |     |     |
 |      |     |     |
 |______|_____|_____|

I can draw a grid without the borders at bottom but the problem is in that if there is only one row in the datagrid the column borders will not go down till the outer border of datagrid I mean if there is only one row that's how my datagrid looks:

  ____________________
 | col1 | col2| col3|
 |______|_____|_____|
 |   r1 |  r1 |  r1 |
 |   r3 |  r2 |  r2 |
 |______|_____|_____|
 |                  |
 |                  |
 |                  |
 |__________________|

which is simple to understand because there is only one row, but what I want is irrespective of the number of rows there should be lines touching to the bottom border of the datagrid, Is there any simple way tot his??

One more problem with it is I want the first row to be selected and focused whenever the form is loaded but no matter how hard I try...it remains unresolved...

Upvotes: 0

Views: 442

Answers (1)

Haris Hasan
Haris Hasan

Reputation: 30097

One way could be to get the last row of DataGrid using this post and set it's height to

height = DataGridHeight - Height of all rows except last one

You may also need to subtract value like DataGridHeaderHeight.

About your second problem.. have you tried setting SelectedIndex of DataGrid to 0 inside loaded event of DataGrid?

Upvotes: 1

Related Questions