DataGrid - centering

A

anonymous

I have created a DataGrid control with checkboxes, TextBoxes,
ComboBoxes, and NumericUpDowns. Since I used the DataGridBoolColumn,
the checkbox is displayed in the center of the cell, horizontally and
vertically aligned.

I want the other cells with data to also be centered so that it is
congruent with the checkbox. I'm having problems centering the data
vertically.

The data always is aligned to the top of the cell, and I want it to be
in the center of the cell.

I've looked at many websites, and this isn't mentioned. Is it
impossible to do this?

Any help?

Thanks very mucn.
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

You will most likely need to provide your own painting and control hosting
logic to achieve that.
To provide your own painting, override the Paint method in the
DataGridColumnStyles.
Providing your own control hosting layout is a more complex task, if you
have source code for custom column styles such as numeric up-down, this
should help you a lot.
 
A

anonymous

Thanks a lot. That was very helpful and gives me some idea how to
approach this problem. I have never overrided the Paint method
before. Does this mean that I have to implement everything or just
override the parts I need to change? I supposed when I research into
this more, it will become more clear. If you happen to know any good
websites/samples, that would be great. Otherwise, don't worry about
it. I'll look it up.

What do you mean by providing my own control hosting layout. Do you
mean that when the cell is clicked, the appropriate control is shown
so that the DataGrid hosts the needed controls?

Thanks again.

Dmitriy Lapshin said:
Hi,

You will most likely need to provide your own painting and control hosting
logic to achieve that.
To provide your own painting, override the Paint method in the
DataGridColumnStyles.
Providing your own control hosting layout is a more complex task, if you
have source code for custom column styles such as numeric up-down, this
should help you a lot.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

anonymous said:
I have created a DataGrid control with checkboxes, TextBoxes,
ComboBoxes, and NumericUpDowns. Since I used the DataGridBoolColumn,
the checkbox is displayed in the center of the cell, horizontally and
vertically aligned.

I want the other cells with data to also be centered so that it is
congruent with the checkbox. I'm having problems centering the data
vertically.

The data always is aligned to the top of the cell, and I want it to be
in the center of the cell.

I've looked at many websites, and this isn't mentioned. Is it
impossible to do this?

Any help?

Thanks very mucn.
 

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

Top