Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSFlexGrid

Status
Not open for further replies.

rnooraei

Programmer
Apr 5, 2005
74
CA
Hi,
I would like to go to second line when I have a long text in a MSFlexGrid row. For example in TextBox control we have multiline properties which we need to set it to True. Do we have such thing for MSFlexGrid?

Thanks
 
With the flxgrid I have been using the code below (found it on several web pages years ago).

Basically you need to put a text box on the screen (in the example below the the textbox name is txtSize
After filling the contents of the flex grid. Loop through the grid and call the ReSizeCellHeight sub sending the row of the grid you are on, the column you want to resize and the name fo the grid you are on.

You will probably need to play with the code some. I simply copied it out of an application we wrote some years ago and have been reusing this code in some applications.


'Delcaration
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long

Const EM_GETLINECOUNT = &HBA


Public Sub ReSizeCellHeight(MyRow As Long, MyCol As Long, stRecGrid As MSFlexGrid)
Dim LinesOfText As Long
Dim HeightOfLine As Long
Dim stBox As TextBox

Set stBox = txtSize

'Set MSFlexGrid to appropriate Cell
stRecGrid.Row = MyRow
stRecGrid.Col = MyCol


'Set textbox width to match current width of selected cell
'txtSize.Width = flxCalls.ColWidth(MyCol)
stBox.Width = stRecGrid.ColWidth(MyCol)

'Set font info of textbox to match FlexGrid control
stBox.Font.Name = stRecGrid.Font.Name
stBox.Font.Size = stRecGrid.Font.Size
stBox.Font.Bold = stRecGrid.Font.Bold
stBox.Font.Italic = stRecGrid.Font.Italic
stBox.Font.Strikethrough = stRecGrid.Font.Strikethrough
stBox.Font.Underline = stRecGrid.Font.Underline

'Set font info of form to match FlexGrid control
Me.Font.Name = stRecGrid.Font.Name
Me.Font.Size = stRecGrid.Font.Size
Me.Font.Bold = stRecGrid.Font.Bold
Me.Font.Italic = stRecGrid.Font.Italic
Me.Font.Strikethrough = stRecGrid.Font.Strikethrough
Me.Font.Underline = stRecGrid.Font.Underline

'Put the text from the selected cell into the textbox
stBox.Text = stRecGrid.Text

'Get the height of the text in the textbox
HeightOfLine = Me.TextHeight(stBox.Text)

'Call API to determine how many lines of text are in text box
LinesOfText = SendMessage(stBox.hwnd, EM_GETLINECOUNT, 0&, 0&)
LinesOfText = LinesOfText + 1
'Check to see if row is not tall enough
If stRecGrid.RowHeight(MyRow) < (LinesOfText * HeightOfLine) Then
'Adjust the RowHeight based on the number of lines in textbox
stRecGrid.RowHeight(MyRow) = (HeightOfLine)
End If
End Sub

Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top