Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# DataGrid WinForm
I am using the code found here to print my windows form datagrid. My question that I have is how can I make the row height greater than the default height?
 
It doesn't look like it showed my link, so here it is:
Another DataGridView Printer[^]
Posted 2-Apr-13 9:02am
Edited 2-Apr-13 9:57am
v3
Comments
Kenneth Haugland at 2-Apr-13 14:50pm
   
And this is WinForms or?
FoxTrotCharlie at 2-Apr-13 14:56pm
   
Sorry, yes this is for a windows form.
Kenneth Haugland at 2-Apr-13 14:57pm
   
Well, cant help you there, but fixed the tag for you :-)
FoxTrotCharlie at 2-Apr-13 14:59pm
   
Apologies for the incorrect tag, but thank you for updating!
Kenneth Haugland at 2-Apr-13 15:02pm
   
No problem. I could help you in WPF but not WinForms. I skipped WinForms and went straight for WPF.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It seems to be simple to achieve:
printer.RowHeight = DGVPrinter.RowHeightSetting.CellHeight;
 
Please, follow the link to the article, go to the end of it to find Comments and Discussion section. There ask a question Wink | ;)
 
You can use DataGridViewRow.Height[^] or DataGridViewRow.MinimumHeight[^] property too.
 
    DataGridViewRow row = dataGridView.Rows[0];
    row.Height = 15;
    //or
    DataGridViewRow row = dataGridView.Rows[1];
    row.MinimumHeight = 40;
  Permalink  
v2
Comments
FoxTrotCharlie at 2-Apr-13 15:40pm
   
I saw that piece, but I thought I would have to actually set the height. Like CellHeight = 32;
 
Should I close this question and post in the QNA of the thread I linked back to? Is that the proper protocol?
Maciej Los at 2-Apr-13 15:47pm
   
Not necessary, but it's better to ask author of article...
See my updated answer.
FoxTrotCharlie at 2-Apr-13 15:58pm
   
Does that element of coding go in my DataGrid load event?
 
When I attempt to use my datagrid I get a compile error of dgvScheduler is a 'field' but is used like a 'type'
 
This is the syntax I used:
dgvScheduler row = dgvScheduler.Rows[0];
row.Height = 15;
Maciej Los at 2-Apr-13 16:09pm
   
NOT dgvScheduler row = dgvScheduler.Rows[0], but DataGridViewRow row = dgvScheduler.Rows[0]
Do you see the difference?
FoxTrotCharlie at 2-Apr-13 16:27pm
   
I do see the difference. Thank you for pointing that out. I get a debug error of Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index.
Maciej Los at 2-Apr-13 16:35pm
   
Ok, create new event for DataGridView: DataSourceChanged[^] and than place this code:
foreach (DataGridViewRow row in DataGridView1.Rows)
{
row.Height = 15;
}
FoxTrotCharlie at 2-Apr-13 16:47pm
   
I added this code:
private void dgvScheduler_DataSourceChanged(object sender, DataGridViewCellEventArgs e)
{
foreach (DataGridViewRow row in dgvScheduler.Rows)
{
row.Height = 15;
}
}
 
but this is not making a change when I load the datagrid. Did I miss a step you listed out for me to follow?
 
EDIT ---
When stepping through my code it looks like this DataSourceChanged event for my DataGrid is not actually hit?!
Maciej Los at 2-Apr-13 17:32pm
   
Default row's height is bigger than 15 ;)
Debug program to check it ;)
FoxTrotCharlie at 2-Apr-13 21:56pm
   
I tried all kinds of sizes, I set it to 600, 6000 also and still no change.
 
When debugging my code never hits the dgvScheduler_DataSourceChnaged event! The way my form works is it loads a form with a blank datagrid. I press the load data button & a inputbox pops up asking who to load data on, once that selection has been made the grid is then populated. There is a separate button to press if the user desires to print the grid.
 
I can post code if necessary, since my code doesn't hit the DataSourceChanged.
Maciej Los at 3-Apr-13 1:35am
   
Weird behavior...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I actually just discovered how to set the row height for a datagrid. I used this code:
 
dgvScheduler.RowTemplate.MinimumHeight = 30;
//And just set the Height to whatever value you are after!
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 7,800
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100