|
i am declaring a class with a function.i will not create any instance for that function in my main form.i need to create the instance only at the runtime..can i do that?
Any suggestions???
Regards...
Selva Shankar
|
|
|
|
|
I am not sure I understand what you are trying to achieve, but if I am guessing correctly, you need to look into late-binding.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
At a guess try declaring the function as "shared".
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
i have found a method...i created a dll...i declared it in runtime using reflection.
Thanks for your informations...Keep posting new ideas...
Regards...
Selva Shankar
|
|
|
|
|
Finally.,i have done this with reflection...Thanks for all your responses...
Regards...
Selva Shankar
|
|
|
|
|
Hi all,
since I found only C#/C++ stuff on my problem, I have to ask you guys for better ways of populating a TreeView control in VB with only a part (!) of the directory structure.
General purpose: I need to simulate a folder explorer which
a) ignores the files in the folder (large number would make it very slow)
That's also the reason why I can't just use FolderBrowserDialog object.
b) only populates subfolders once a parent folder it is expanded (same reason - performance)
By now I have the following solution (which basically works):
Private Sub TreeView_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView.BeforeExpand
'avoid errors when access denied, i.e. system folders
On Error Resume Next
For Each ChildNode As TreeNode In TreeView.SelectedNode.Nodes
'For Each ChildNode As TreeNode In TreeView.SelectedNode.Nodes
' Mehrfaches Füllen vermeiden!
If ChildNode.Nodes.Count > 0 Then Exit Sub
Dim di As DirectoryInfo = New DirectoryInfo(ChildNode.FullPath)
Dim subDirs() As DirectoryInfo = di.GetDirectories("*", SearchOption.TopDirectoryOnly)
For i = 1 To subDirs.Length
Dim actSub As New TreeNode(subDirs(i).ToString)
ChildNode.Nodes.Add(actSub)
actSub.ImageIndex = Ico_FldClosed
Next
Next
End Sub
Problem: It refers to "TreeView.SelectedNode.Nodes", so that the subfolders aren't filled with their subfolders (i.e. grandchildren) in case the user expands the tree by clicking on the "+" symbol without selecting the node first.
Which other property or method could I use? Maybe someone even has a much better solution... I'd really appreciate every good advice!
Thanks
Michael
|
|
|
|
|
Your "Problem" description isn't very clear. But, what you normally do in this situation is add each subfolder and populate it with a dummy blank node so the folder gets a "plus" next to it. When the user clicks the plus, your code has to check if the dummy node is there, and if it is, delete it, then populate the folder appropriately.
|
|
|
|
|
Thanks for the idea, Dave. Let me try to make it clearer:
- On the first level I only show the drives (e.g. "C:\") in the tree view, populated with nodes for existing subdirectories (e.g. "C:\Test", "C:\Real" etc.) in the "form_Load" event. This way, the nodes only have a "plus" once there are subdirectories existing! A drive without subdirectories (e.g. empty removable) doesn't have a "plus".
- Once the user selects and expands a node (e.g. "+ C:\"), I use the the "TreeView_BeforeExpand" event to populate the child nodes with the next level of subdirectories (grand children --> e.g. "C:\Test\TestDir1", "C:\Test\TestDir2" etc.). Again: If "C:\Real" doesn't have any subdirectories, it's not populated with "grandchild" nodes and therefore doesn't have a "plus" when the "C:\" node expands, while the other node ("+ C:\Test") has a "plus".
Other words: The event or the parent node populates all the child nodes with probable grandchild nodes before the child nodes are shown (without "plus" if they don't have subdirectories).
- For performance reasons I ONLY populate the children of the node that the user wants to expand. Not knowing it any better, I use the "SelectedNode" property in my code to find out which node to populate.
Up to here it works fine - and I think even better than with dummies, because adding dummies I have the "plus" even for folders without subfolders... don't I?
But here's my real problem:In case the user wants to expand the node by clicking on the "plus" ---> without explicitly selecting (or double-clicking) the drive letter (!) --- then my whole code doesn't populate the subfolders because my "for ... next" loop says "..each ChildNode ... in Treeview.SelectedNode".
Obviously clicking the "plus" doesn't select the relevant node! Which event is raised when the user clicks "plus" in the TreeView control?
It's a bit hard for me to explain... hope you know what I mean... otherwise I'd try again
modified on Thursday, October 16, 2008 5:46 PM
|
|
|
|
|
Michael Schäuble wrote: Up to here it works fine - and I think even better than with dummies, because adding dummies I have the "plus" even for folders without subfolders... don't I?
Yep. The subfolder isn't populated until the user clicks on the plus. So, if there are an excessive number of sub-subfolders, you're not wasting time populating folders that the user isn't intersted in.
Michael Schäuble wrote: my "for ... next" loop says "..each ChildNode ... in Treeview.SelectedNode".
The event you're looking for is BeforeExpand. With it, you get the node that's expanding. You don't need SelectedNode at all.
|
|
|
|
|
Somehow I'm still stuck... BeforeExpand is the event I used in the code posted. Could you please have another look?
Starting that event with "Dim actNode as TreeNode = TreeView.SelectedNode" (like I did before) I run into my old problem.
Which command would I use to get the node that's expanding into "actNode"? If I just define it with "Dim actNode as TreeNode", then my "actNode" variable (needed to loop through the sub-nodes when populating these) is "Nothing" and the code doesn't work ...
|
|
|
|
|
Michael Schäuble wrote: Dim actNode as TreeNode = TreeView.SelectedNode
Nope. Look at the eventargs you get in the method header, you know, the ByVal e As TreeView... part?? In the object, e , you get the node that is being expanded.
Private Sub TreeView1_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) _
Handles TreeView1.BeforeExpand
Dim actNode As TreeNode = e.Node
...
End Sub
|
|
|
|
|
Thanks for the detailed help, Dave! I haven't dared to mess with the "e.-Stuff" yet...
Works like charms now. I'll test it under real conditions tonight. Since I haven't found such information (VB code) I guess it could even make my first article for the community
Regards
Michael
|
|
|
|
|
Michael Schäuble wrote: I haven't dared to mess with the "e.-Stuff" yet...
You better start, and quick! That's where the most useful stuff comes from when handling events.
|
|
|
|
|
Hello everyone!
Really confused by this problem. Usually I can search and find an answer, but I'm not even sure how to search for it. I have a function (obviously includes all days of the week, but shortened for shortness' sake):
Function getlabel(ByVal day As DayOfWeek, ByVal calendarRow As Integer) As System.Windows.Forms.Label
Select Case day 'Get a label name
Case DayOfWeek.Sunday
Select Case calendarRow
Case 1
Return su1
Case 2
Return su2
Case 3
Return su3
Case 4
Return su4
Case 5
Return su5
Case 6
Return su6
End Select
End Select
End Function
If I call it by:
Dim CurrentDayNum As Integer = CInt(getlabel(getCurrentDayOfWeek(dayShortName), CInt(ClickedLabel.Name.Substring(0, 4))).Name)
It returns nothing.
If I call it by a direct "DayOfWeek":
Dim CurrentDayNum As Integer = CInt(getlabel(DayOfWeek.Thursday, CInt(ClickedLabel.Name.Substring(0, 4))).Name)
It works fine, and returns the proper label.
When I type getCurrentDayOfWeek(dayShortName) into the debugger, it gives me: Thursday
getCurrentDayOfWeek is a Function As DayOfWeek
I hope that wasn't too confusing, I can be that way. Anybody have any suggestions?
|
|
|
|
|
is your first call Sunday? where is CASE 0?
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
There is no Case 0. It should always be sending a DayOfWeek.
There is a similar Case statement for each day of the week.
Or maybe I didn't understand your question.
|
|
|
|
|
oooooooops misread your code.
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
Is your return type of getCurrentDayOfWeek(), DayOfWeek?
In which point did you try getCurrentDayOfWeek(dayShortName) in the debugger?
Intelligence is almost useless for those who have nothing else!
Email: caiokf@gmail.com
|
|
|
|
|
Caio Kinzel Filho wrote: Is your return type of getCurrentDayOfWeek(), DayOfWeek?
Yes it is.
Caio Kinzel Filho wrote: In which point did you try getCurrentDayOfWeek(dayShortName) in the debugger?
As soon as dayShortName was set, right before the problem function call.
|
|
|
|
|
can you post your getCurrentDayOfWeek function? I tryied here and works fine...
Intelligence is almost useless for those who have nothing else!
Email: caiokf@gmail.com
|
|
|
|
|
No problem.
Private Function getCurrentDayOfWeek(ByVal dayName As String) As DayOfWeek
Select Case dayName
Case "su"
getCurrentDayOfWeek = DayOfWeek.Sunday
Case "mo"
getCurrentDayOfWeek = DayOfWeek.Monday
Case "tu"
getCurrentDayOfWeek = DayOfWeek.Tuesday
Case "we"
getCurrentDayOfWeek = DayOfWeek.Wednesday
Case "th"
getCurrentDayOfWeek = DayOfWeek.Thursday
Case "fr"
getCurrentDayOfWeek = DayOfWeek.Friday
Case "sa"
getCurrentDayOfWeek = DayOfWeek.Saturday
End Select
Return getCurrentDayOfWeek
End Function
|
|
|
|
|
I did this:
MsgBox(getlabel(DayOfWeek.Sunday, 1))
MsgBox(getlabel(getCurrentDayOfWeek("su"), 1))
with your function and (for shortness..):
Function getlabel(ByVal day As DayOfWeek, ByVal calendarRow As Integer) As String
Select Case day 'Get a label name
Case DayOfWeek.Sunday
Select Case calendarRow
Case 1
Return "Sunday"
End Select
Case DayOfWeek.Monday
Select Case calendarRow
Case 1
Return "Monday"
End Select
Case DayOfWeek.Tuesday
Select Case calendarRow
Case 1
Return "Tuesday"
End Select
End Select
End Function
And it works...other than that...i think you will have to post your entire code...
Intelligence is almost useless for those who have nothing else!
Email: caiokf@gmail.com
|
|
|
|
|
There is no way the CInt(ClickedLabel.Name.Substring(0, 4))).Name could have changed between your calls, and have no valid data in your call using getCurrentDayOkWeek ??
Intelligence is almost useless for those who have nothing else!
Email: caiokf@gmail.com
|
|
|
|
|
|
The link doesn't work for me...send it to my email and I will take a look...caiokf@gmail.com
Regards
Intelligence is almost useless for those who have nothing else!
Email: caiokf@gmail.com
|
|
|
|