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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update FlexGrid Without TextBox Or Similar

Status
Not open for further replies.

LPlates

Programmer
Jun 5, 2003
554
AU
I found this on the and tweaked it a little. After seeing many discussions on this I thought I'd share it with you. Open a new project, add a MSHFlexgrid Control and the following code...

[blue]Option Explicit

Private Declare Function [/blue]LockWindowUpdate [blue]Lib [/blue]"user32" ([blue]ByVal [/blue]hwndLock [blue]As Long[/blue]) As Long

[blue]Private [/blue]RowsVisible [blue]As Integer

Private Sub [/blue]Form_Load()

[blue]With [/blue]FlexGrid

.ColWidth(0) = 300
.ColWidth(1) = 1920
.ColWidth(2) = 900
.ColWidth(3) = 1095
.ColWidth(4) = 735
.ColWidth(5) = 600
.ColWidth(6) = 540
.ColWidth(7) = 915
.TextMatrix(0, 0) = "Sr"
.TextMatrix(0, 1) = "Clients"
.TextMatrix(0, 2) = "Time"
.TextMatrix(0, 3) = "Date"
.TextMatrix(0, 4) = "Code"
.TextMatrix(0, 5) = "Cost"
.TextMatrix(0, 6) = "Unit"
.TextMatrix(0, 7) = "Amount"
.AddItem "12" + Chr(9) + "Inter Continental Potato Traders" + Chr(9) + "10:40 AM" + Chr(9) + "2001/04/05" + Chr(9) + "M88" + Chr(9) + "10" + Chr(9) + "5" + Chr(9) + "50.00", 1
.AddItem "11" + Chr(9) + "James Bond [blue]Private [/blue]Eye Service" + Chr(9) + "11:00 AM" + Chr(9) + "2001/04/05" + Chr(9) + "IMX32" + Chr(9) + "100" + Chr(9) + "25" + Chr(9) + "2500.00", 1
.AddItem "10" + Chr(9) + "Jhon & Jony Jewllery Suppliers" + Chr(9) + "12:10 PM" + Chr(9) + "2001/04/05" + Chr(9) + "MX8" + Chr(9) + "8" + Chr(9) + "5" + Chr(9) + "40.00", 1
.AddItem "9" + Chr(9) + "Soft [blue]and [/blue]Smooth Business Software" + Chr(9) + "12:40 PM" + Chr(9) + "2001/04/05" + Chr(9) + "A4G" + Chr(9) + "111" + Chr(9) + "5" + Chr(9) + "555.00", 1
.AddItem "8" + Chr(9) + "Petro, The Odd Job Man" + Chr(9) + "01:40 PM" + Chr(9) + "2001/04/05" + Chr(9) + "GM9" + Chr(9) + "10" + Chr(9) + "8" + Chr(9) + "80.00", 1
.AddItem "7" + Chr(9) + "Carpet World" + Chr(9) + "02:00 PM" + Chr(9) + "2001/04/05" + Chr(9) + "A6L" + Chr(9) + "66.33" + Chr(9) + "5" + Chr(9) + "331.65", 1
.AddItem "6" + Chr(9) + "Anita Publishers" + Chr(9) + "03:20 PM" + Chr(9) + "2001/04/05" + Chr(9) + "XL2" + Chr(9) + "86.49" + Chr(9) + "18" + Chr(9) + "1556.82", 1
.AddItem "5" + Chr(9) + "Doom Nurshing Home Pvt Ltd" + Chr(9) + "03:25 PM" + Chr(9) + "2001/04/05" + Chr(9) + "CBZ33" + Chr(9) + "59.99" + Chr(9) + "7" + Chr(9) + "419.93", 1
.AddItem "4" + Chr(9) + "Solid Gold Furnitures" + Chr(9) + "03:20 PM" + Chr(9) + "2001/04/05" + Chr(9) + "XL2" + Chr(9) + "86.49" + Chr(9) + "18" + Chr(9) + "1556.82", 1
.AddItem "3" + Chr(9) + "K Computer Parts Dealer" + Chr(9) + "03:25 PM" + Chr(9) + "2001/04/05" + Chr(9) + "CBZ33" + Chr(9) + "59.99" + Chr(9) + "7" + Chr(9) + "419.93", 1
.AddItem "2" + Chr(9) + "Solid Gold Furnitures" + Chr(9) + "03:20 PM" + Chr(9) + "2001/04/05" + Chr(9) + "XL2" + Chr(9) + "86.49" + Chr(9) + "18" + Chr(9) + "1556.82", 1
.AddItem "1" + Chr(9) + "J K International Man Power Suppliers Pvt Ltd" + Chr(9) + "03:25 PM" + Chr(9) + "2001/04/05" + Chr(9) + "CBZ33" + Chr(9) + "59.99" + Chr(9) + "7" + Chr(9) + "419.93", 1

[blue]End With

[/blue]CountVisibleRows
[blue]End Sub

Private Sub [/blue]CountVisibleRows()
[blue]Dim [/blue]OldTop [blue]As Long
Dim [/blue]RowCount [blue]As Integer

On Error Resume Next

Do Until [/blue]Err.Number <> 0
FlexGrid.Row = FlexGrid.Row + 1
[blue]Loop
[/blue]RowCount = FlexGrid.Row

OldTop = FlexGrid.TopRow
LockWindowUpdate FlexGrid.hWnd
FlexGrid.TopRow = RowCount - 1
RowsVisible = RowCount - FlexGrid.TopRow
FlexGrid.TopRow = OldTop
LockWindowUpdate 0
[blue]End Sub

Private Sub [/blue]FlexGrid_KeyPress(KeyAscii [blue]As Integer[/blue])
[blue]With [/blue]FlexGrid
[blue]Select Case [/blue]KeyAscii
[blue]Case [/blue]vbKeyReturn
[green]'move to next cell.
[/green][blue]If [/blue].Col + 1 <= .Cols - 1 [blue]Then
[/blue].Col = .Col + 1
[blue]Else
If [/blue].Row + 1 <= .Rows - 1 [blue]Then
[/blue].Row = .Row + 1
.Col = 1
[blue]Else
[/blue].Row = 1
.Col = 1
.TopRow = .Row
[blue]End If
End If

If [/blue].Row > .TopRow + RowsVisible [blue]Then
[/blue].TopRow = .TopRow + 1
[blue]End If

Case [/blue]vbKeyBack
[green]'remove the last character, if any.
[/green][blue]If [/blue]Len(.Text) [blue]Then
[/blue].Text = Left(.Text, Len(.Text) - 1)
[blue]End If

Case Is [/blue]< 32
[green]'Do Nothing

[/green][blue]Case Else
[/blue].Text = .Text & Chr(KeyAscii)

[blue]End Select
End With
End Sub
[/blue]
 
Any comments?
 
For me it's probably easier (and more versatile) to overlay another control. Then you can use textbox, dtpicker, combo or whatever.

It's all covered fairly comprehensively in faq222-3262

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Well, it's nearly as scary as overlaying a control, and of course the advantage of overlaying with a textbox or combo etc is that you get that control's events exposed as well...

I must admit though, I'm amazed that FlexGrid is not editable by the end user - it would be so useful if the user could edit it...

mmilan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top