|
First, you can't check for null references with If x = Nothing ... - you have to use If x Is Nothing ...
Second, you can't perform reference comparison on value types. If x is a value type, If x Is Nothing ... will not compile.
Try something like:
Public Class Test
Private _id As Long
Private _idSet As Boolean = False
Public Property ID As Long
Get
Return _id
End Get
Set(ByVal Value As Long)
_id = Value
_idSet = True
End Set
End Property
Public Sub Save()
If _idSet Then
'Save Data
Else
'Throw exception
End If
End Sub
End Class
|
|
|
|
|
my treeview is very very laggy when calling TreeView.Nodes.Clear .. ive found that if i call TreeView.Invisible = TRUE before clearing the tree, then make it visible again afterwards that it is much much faster.. in C++ i use a comand SetRedraw(FALSE) before clearing the list, then SetRedraw(TRUE) afterwards.. is there anything like this for VB, or is making the list invisible the only hack?
populating the list is just as slow as well unless i make it invisible first.. anyway to turn off the redraw without making it invisible?
thanks!
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
Yes, this is super easy:
TreeView.BeginUpdate()
TreeView.Nodes.Clear
TreeView.EndUpdate()
|
|
|
|
|
Doh! Sorry, using .NET here...
Anyway, use the API Function "LockWindowUpdate".
Public Declare Function LockWindowUpdate Lib "user32" (ByVal hWndLock As Long) As Long
Then, use this function when Populating or Clearing the TreeView.
Call LockWindowUpdate(Tree.hWnd)
'Populate or Clear Nodes
Call LockWindowUpdate(0)
Always remember to "UnLock" after you are done, otherwise it never repaints. Also, if you are updating more controls (i.e. ComboBoxes) that are on the same Form, just Lock the Whole Form that way painting will not occur on any controls.
I use this in my App all the time and it has sped up the process of loading Forms by up to 70%!
|
|
|
|
|
thanks a ton for the suggestions, works well!
thanks again!
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
Actually, I figured I would Post this here. This function will Lock as many Windows as you want from Redrawing...unlike the "LockWindowUpdate" Function.
'API Declarations (.NET)
Private Declare Ansi Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
'Routine to Lock a Window from Repainting
Public Sub LockWindowUpdate(ByVal Handle As IntPtr, ByVal Lock As Boolean)
Const WM_SETREDRAW As Integer = &HB
'Enable / Disable Drawing
Call SendMessage(Handle, WM_SETREDRAW, Math.Abs(CInt(Lock)), 0)
End Sub
'API Declarations (VB6)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Routine to Lock a Window from Repainting
Public Sub LockWindowUpdate(ByVal Handle As Long, ByVal Lock As Boolean)
Const WM_SETREDRAW As Long = &HB
'Enable / Disable Drawing
Call SendMessage(Handle, WM_SETREDRAW, Abs(CInt(Lock)), 0)
End Sub
|
|
|
|
|
I have a legacy app in SETUP form only which appears to be created with VB version 5. Are there any command line parameters for this setup?
Thanks
Davy
Weblog, Ramblings and more...
www.latedecember.com
|
|
|
|
|
Davy Mitchell wrote:
Are there any command line parameters for this setup?
More info....
Nick Parker
May your glass be ever full.
May the roof over your head be always strong.
And may you be in heaven half an hour before the devil knows you’re dead. - Irish Blessing
|
|
|
|
|
|
May I know how to launch an external exe file from my application. Just like launching an external Word Document from application.
Besides that, any code that can be used to prevent an application that being launched more than one time.
please help. thanx in advance.
|
|
|
|
|
Desmond wrote:
May I know how to launch an external exe file from my application.
Use the Shell command. There are ways to check to see if an instance of a Word or Excel object is already in existence such as GetObject . Hope this helps.
Nick Parker
May your glass be ever full.
May the roof over your head be always strong.
And may you be in heaven half an hour before the devil knows you’re dead. - Irish Blessing
|
|
|
|
|
Hi,
You may use Process.Start (from System.Diagnostics.Process). That provides granular control over the process you are starting.
Perhaps the following URL should open MSDN Documentation too:
ms-help://MS.NETFrameworkSDK/cpref/html/frlrfsystemdiagnosticsprocessclassstarttopic.htm
process.Start("http://www.codeproject.com") where process is an object of Process opens the default browser and navigates to codeproject.com
While shell might still execute system commands, you might not be able to control execution of those programs to the level that Process allows you to do so.
Deepak Kumar Vasudevan
http://deepak.portland.co.uk/
|
|
|
|
|
Hello
I've got a problem with VB.NET/Windows Application. I have a DataSet, and I want to connect columns from different DataTables to one view in the DataGrid. Is this possible?
/e
|
|
|
|
|
Greetings
As far as I know that is not possible. One way around is to create a temporary datatable with desired columns and copy the data there. This, however, does consume some amount of memory. It should not be an issue if the data is not very big.
Nothing else comes to my mind right now.
|
|
|
|
|
I'm trying to draw a single black border around my dialog using the following code:
Private Sub LogInDialog_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim Rect As New Rectangle(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width - 1, e.ClipRectangle.Height - 1)
e.Graphics.DrawRectangle(Pens.Black, Rect)
End Sub
I have a ComboBox control on the page along with some text fields and such. When I drop the ComboBox's List control, then contract it again, there are marks from where the listbox was (I can see it behind the other controls on the page below the ComboBox). I tried bringing the control to the front, but that didn't help. Any ideas?
Thanks in advance for any help.
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
Jamie Nordmeyer wrote:
Any ideas?
Yep, but I know there is a better solution, however this will work for you as I just tried it.
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Me.Refresh()
End Sub
Let me know, hope it helps.
Nick Parker
May your glass be ever full.
May the roof over your head be always strong.
And may you be in heaven half an hour before the devil knows you’re dead. - Irish Blessing
|
|
|
|
|
Hey there, Nick. Thanks for the reply. Actually, I figured it out at the end of the day yesterday, then promptly kicked myself. I was using the clipping rectange (e.ClipRectangle), which only specifies the area that needs updating, not the whole dialog (been doing ASP.NET stuff for the last year, so I forgot a few of my 'Windows programming rules'). Anyway, I changed all the e.ClipRectangle parts to DisplayRectangle (e.ClipRectangle.X to Me.DisplayRectangle.X), and it works great.
Again, thanks for thought.
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
Hello Jamie:
I am trying to do the similar thing. i need to draw a rectangle and fill with white color. Any idea? Thanks
Zulfikar Ali
|
|
|
|
|
From with a paint event handler, you can use
e.Graphics.FillRectangle(Color.White, Rect)
replacing Rect with the rectangle you want to fill. Did that answer your question?
Jamie.
Jamie Nordmeyer
Portland, Oregon, USA
|
|
|
|
|
Hi,
First, it is the first time I'm doing something in VB.
I have a problem :
I want to make a vb script to create a registry key in our buildAll.bat file, which is builing all our VC++ dlls/exes.
Here is my script :
<br />
Dim MyPath <br />
MyPath = CurDir<br />
Dim intDoIt<br />
intDoIt = MsgBox(MyPath)<br />
Set WshShell = WScript.CreateObject("WScript.Shell")<br />
WshShell.RegWrite "HKLM\SOFTWARE\Company\Product\InstallDir", MyPath<br />
As you can see, I'm trying to set the install path from the current path.
The problem is that the script doesn't works : the MyPath variable is empty.
Any idea ?
thanks in advance.
Stephane
www.exotk.org
|
|
|
|
|
forget it !
I created a win32 exe doing it.
Stephane
www.exotk.org
|
|
|
|
|
If you have the latest scripting engine (5.6), you can use the CurrentDirectory property of the Shell object:
Dim WshShell : Set WshShell = WScript.CreateObject("WScript.Shell")
Dim MyPath : MyPath = WshShell.CurrentDirectory
Dim intDoIt : intDoIt = MsgBox(MyPath)
WshShell.RegWrite "HKLM\SOFTWARE\Company\Product\InstallDir", MyPath
|
|
|
|
|
What is about MyPath = WScript.Path?
Or using WScript.ScriptFullName and WScript.ScriptName?
With best wishes,
Vita
|
|
|
|
|
Which attribute should I set?
Thanks
|
|
|
|
|
The following will ensure the form is kept on top:
Option Explicit
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, _
ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Const HWND_TOPMOST = -1
Const SWP_SHOWWINDOW = &H40
Const SWP_DRAWFRAME = &H20
Private Sub Form_Load()
Dim retval As Long
retval = SetWindowPos(Me.hwnd, HWND_TOPMOST, 100, 100, 100, 100, SWP_DRAWFRAME Or SWP_SHOWWINDOW)
End Sub
|
|
|
|