|
-
Jul 15th, 2002, 01:46 AM
#1
Thread Starter
PowerPoster
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.
-
Jul 15th, 2002, 05:17 AM
#2
Member
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:
Public Sub CustomWait(ByVal Seconds As Long)
MyTimer.Interval = 1000 'aka 1 second
MyTimer.Tag = Seconds
MyTimer.Enabled = True
Do 'Wait until Timer has stopped
DoEvents
Loop Until MyTimer.Enabled = False
Private Sub MyTimer_Timer
MyTimer.Tag = MyTimer.Tag-1
If MyTimer.Tag <= 0 Then MyTimer.Enabled = False 'Stop
End Sub
HTH
Felix
-
Jul 16th, 2002, 01:49 AM
#3
Thread Starter
PowerPoster
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
-
Jul 16th, 2002, 09:17 AM
#4
Thread Starter
PowerPoster
-
Jul 16th, 2002, 11:37 AM
#5
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:
'In a module
Public Const DT_CENTER = &H1
Public Const DT_WORDBREAK = &H10
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
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
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
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
Global Cnt As Long, sSave As String, sOld As String, Ret As String
Dim Tel As Long
Function GetPressedKey() As String
For Cnt = 32 To 128
'Get the keystate of a specified key
If GetAsyncKeyState(Cnt) <> 0 Then
GetPressedKey = Chr$(Cnt)
Exit For
End If
Next Cnt
End Function
Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Ret = GetPressedKey
If Ret <> sOld Then
sOld = Ret
sSave = sSave + sOld
End If
End Sub
'In a form
Private Sub Form_Load()
'KPD-Team 1999
'URL: [url]http://www.allapi.net/[/url]
Me.Caption = "Key Spy"
'Create an API-timer
SetTimer Me.hwnd, 0, 1, AddressOf TimerProc
End Sub
Private Sub Form_Paint()
Dim R As RECT
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."
'Clear the form
Me.Cls
'API uses pixels
Me.ScaleMode = vbPixels
'Set the rectangle's values
SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
'Draw the text on the form
DrawTextEx Me.hDC, mStr, Len(mStr), R, DT_WORDBREAK Or DT_CENTER, ByVal 0&
End Sub
Private Sub Form_Resize()
Form_Paint
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Kill our API-timer
KillTimer Me.hwnd, 0
'Show all the typed keys
MsgBox sSave
End Sub
Hope that helps...
Adios,
Off home for a J 
Woka
-
Jul 17th, 2002, 02:49 AM
#6
Thread Starter
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|