Results 1 to 6 of 6

Thread: 2 qs : Timer and How do I hide/unhide columns in a list view?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    2 qs : Timer and How do I hide/unhide columns in a list view?

    hi,
    2 questions
    For a listview, I want the user to choose the columns for a specified output though all the columns will be filled with data , i want to display only those columns which the user selects(Like we have it in windows explorer). Currently I make the width of the hidden column as - 0 but that the user can just keep his mouse on the header and drag to see the hidden column. How do I actually hide it???

    Second question:

    I have just recently find out that one cannot set the interval time of a timer for than 65000 millisecs that is apporx a minute. How do I set the interval of a timer for more than a minute say 3 minutes?

    Thanks.

  2. #2
    Member
    Join Date
    Sep 1999
    Location
    Zurich, Switzerland
    Posts
    55
    1) I recently coded somethin similar but used a DataGrid, which loads my recordset (up to 20'000 records) much faster. I did it that way: I made a sub-recordset to be displayed in the Data Grid, but afterwards, after the user did his selections, processing is done with the full recordset.

    2) add the following code:
    VB Code:
    1. Public Sub CustomWait(ByVal Seconds As Long)
    2.  
    3. MyTimer.Interval = 1000 'aka 1 second
    4. MyTimer.Tag = Seconds
    5. MyTimer.Enabled = True
    6.  
    7. Do 'Wait until Timer has stopped
    8.     DoEvents
    9. Loop Until MyTimer.Enabled = False
    10.  
    11.  
    12.  
    13. Private Sub MyTimer_Timer
    14.  
    15. MyTimer.Tag = MyTimer.Tag-1
    16. If MyTimer.Tag <= 0 Then MyTimer.Enabled = False 'Stop
    17.  
    18. End Sub

    HTH
    Felix

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089
    Thanks for the input pal.

    Regarding the first question: I wasnt worried about the speed to display the records in the lsitveiw but to "Hide" a column once the
    user deselects it. I have absolutely no idea how can I actually hide a column (not remove it) in a listview.

    The second timer one - the thing is that what you are doing is checking the timer thing every "1 second" till the time we have specified occurs - Thats precisely what I am doing at present (though a little bit differently). But I do not want to keep checking this thing because I already know the event I am looking for wont occur for some time. So I wanted the timer interval to set to that time (It can be any numbers of MINUTES or HOURS)
    Basically - I shd be telling you a bit of background,( Perphaps you will have a better idea): I have made a alerter kindof utility wherein I alert the user when he sets his alarm for a particular time. Now I record this time say its after two hours (for eg) now I set the timer Interval for one minute and each time in the _timer event I check whether is it the corect time to alert him - if not then again the timer interval to the next minute. Now this is the scenario, if I could directly set the timer interval for two hours I do not need to check for it every minute (and thus save CPU and memory usage for my prg). Any ideas.....Thanks

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

  5. #5
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking Arrrr...5:40pm and still at wrk...*sigh*

    You can't hide a column in a listview Listviews are VERY limited in functionality...you could always have a look at sGrid on vbAccelerator.com

    The timer thing...Hmmmmmm. You can use API...here's the code...
    VB Code:
    1. 'In a module
    2. Public Const DT_CENTER = &H1
    3. Public Const DT_WORDBREAK = &H10
    4. Type RECT
    5.     Left As Long
    6.     Top As Long
    7.     Right As Long
    8.     Bottom As Long
    9. End Type
    10. Declare Function DrawTextEx Lib "user32" Alias "DrawTextExA" (ByVal hDC As Long, ByVal lpsz As String, ByVal n As Long, lpRect As RECT, ByVal un As Long, ByVal lpDrawTextParams As Any) As Long
    11. Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    12. Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
    13. Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    14. Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    15. Global Cnt As Long, sSave As String, sOld As String, Ret As String
    16. Dim Tel As Long
    17. Function GetPressedKey() As String
    18.     For Cnt = 32 To 128
    19.         'Get the keystate of a specified key
    20.         If GetAsyncKeyState(Cnt) <> 0 Then
    21.             GetPressedKey = Chr$(Cnt)
    22.             Exit For
    23.         End If
    24.     Next Cnt
    25. End Function
    26. Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
    27.     Ret = GetPressedKey
    28.     If Ret <> sOld Then
    29.         sOld = Ret
    30.         sSave = sSave + sOld
    31.     End If
    32. End Sub
    33.  
    34. 'In a form
    35. Private Sub Form_Load()
    36.     'KPD-Team 1999
    37.     'URL: [url]http://www.allapi.net/[/url]
    38.     'E-Mail: [email][email protected][/email]
    39.     Me.Caption = "Key Spy"
    40.     'Create an API-timer
    41.     SetTimer Me.hwnd, 0, 1, AddressOf TimerProc
    42. End Sub
    43. Private Sub Form_Paint()
    44.     Dim R As RECT
    45.     Const mStr = "Start this project, go to another application, type something, switch back to this application and unload the form. If you unload the form, a messagebox with all the typed keys will be shown."
    46.     'Clear the form
    47.     Me.Cls
    48.     'API uses pixels
    49.     Me.ScaleMode = vbPixels
    50.     'Set the rectangle's values
    51.     SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
    52.     'Draw the text on the form
    53.     DrawTextEx Me.hDC, mStr, Len(mStr), R, DT_WORDBREAK Or DT_CENTER, ByVal 0&
    54. End Sub
    55. Private Sub Form_Resize()
    56.     Form_Paint
    57. End Sub
    58. Private Sub Form_Unload(Cancel As Integer)
    59.     'Kill our API-timer
    60.     KillTimer Me.hwnd, 0
    61.     'Show all the typed keys
    62.     MsgBox sSave
    63. End Sub
    Hope that helps...

    Adios,
    Off home for a J

    Woka

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    thanks

    Thanks. Thanks a lot. Really didnt know about the api. Even MSDN has an example.
    Thanks once again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width