|
-
Jan 16th, 2006, 06:57 AM
#1
Thread Starter
Fanatic Member
DataGrid - Row Height?
I seem to be having problems finding the height of a row in a DataGrid.
I have a DataGrid control in which the user can resize the rows manually. I need to be able to access the row heights in code and possibily change them if necessary.
I can get to an individual row by the following code:
VB Code:
dsTarget = mdgdTarget.DataSource
dtTarget = dsTarget.Tables.Item(mdgdTarget.DataMember)
drTarget = dtTarget.Rows.Item(intRow)
But there is no Height property?
Last edited by simonm; Jan 16th, 2006 at 07:05 AM.
Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment. 
-
Jan 16th, 2006, 07:28 AM
#2
Re: DataGrid - Row Height?
A DataRow is a row of data in a DataTable. It isn't going to have a Height property because it is not a UI element. My guess is that, like many other controls, the height of a row in a DataGrid is automatically set relative to the size of the Font used. You'd probably have to draw all or part of the DataGrid yourself to control the row height. That's not definitive mind you. If it can be done I'd guess you'd find out how from the Windows Forms FAQ link in my sig, which has heaps of information on using the DataGrid and many other controls.
-
Jan 16th, 2006, 08:18 AM
#3
Thread Starter
Fanatic Member
Re: DataGrid - Row Height?
I don't know what you mean by it not being a UI element. The user can quite easilly adjust the row height of individual rows.
In addition, there is a PreferredRowHeight property of both the DataGrid and the TableStyle objects that controls the default row height.
However I'll check out that link in your sig anyway...
p.s. that's one hell of a sig!
Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment. 
-
Jan 16th, 2006, 02:43 PM
#4
Re: DataGrid - Row Height?
You can try looking into DataGridColumnStyles, I believe if you do it correctly you can specify the row heights, however I was unable to do it a while back when trying, so I am not 100% sure...
-
Jan 16th, 2006, 06:55 PM
#5
Re: DataGrid - Row Height?
 Originally Posted by simonm
I don't know what you mean by it not being a UI element. The user can quite easilly adjust the row height of individual rows.
In addition, there is a PreferredRowHeight property of both the DataGrid and the TableStyle objects that controls the default row height.
However I'll check out that link in your sig anyway...
p.s. that's one hell of a sig!
You need to distinguish between a row in your DataGrid and a row in your DataTable. In the code you posted the "drTarget" variable is a DataRow, which is not a UI element. You don't have to display a DataRow in a DataGrid so why should the DataRow object have property that controls the height of a row in a DataGrid? That's like saying that the String class should have a property that controls the height of a TextBox. As for the PreferredRowHeight, that is for the entire grid. I assumed that you wanted to affect individual rows, but perhaps not. The help topic for that property also states that you have to set it before assigning a DataSource, so you'd have to re-assign an existing DataSource for it to have an effect.
-
Jan 17th, 2006, 04:44 AM
#6
Thread Starter
Fanatic Member
Re: DataGrid - Row Height?
Yes, I do want to affect individual rows. And I am perfectly willing to accept that I am going down the wrong path looking at datarows of datatables.
But I see no way of getting to the rows of the datagrid either.
Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment. 
-
Jan 17th, 2006, 05:01 AM
#7
Re: DataGrid - Row Height?
I don't think there is supposed to be a way. The PreferredRowHeight presumably sets the default height of all rows and individual rows will be taller if the data they are displaying requires it. That's why I said previously that you would probably have to draw the grid yourself, which is bound to be an enormous hassle. You could look around for a third-party component that already provides that functionality.
-
Jan 17th, 2006, 07:02 AM
#8
Thread Starter
Fanatic Member
Re: DataGrid - Row Height?
As I have said, the user can quite easilly adjust the row heights manually. But the rows do not automatically expand to fit the contents of the cells (specifically when the text is on multiple lines in one cell). It would seem to me to be a enormous oversight for there to be lacking a programatic interface to access this when it is a part of the UI.
Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment. 
-
Jan 17th, 2006, 07:16 AM
#9
Re: DataGrid - Row Height?
 Originally Posted by simonm
As I have said, the user can quite easilly adjust the row heights manually.
Is that so? I thought you meant that you wanted to be able to do that but couldn't. I haven't used DataGrids much at all myself so I wasn't aware of that. It doesn't help you much but it seems that you can access the rows of the grid directly in the new DataGridView as there is a DataGridViewRow class that has a Height property.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|