|
thanks for replying:
it's the first idea that i do it but , it remain existed in listview and the user can resize it , son it will appear again ,
I have tried to catch the listview resize event to set the column width to 0 again but it doesn't works. (There will be a recursive call)
-- modified at 5:52 Wednesday 10th May, 2006
|
|
|
|
|
make th ewidth of the column 0(Zero)
Thanks
|
|
|
|
|
it's the first idea that i do it but , it remain existed in listview and the user can resize it , son it will appear again ,
I have tried to catch the listview resize event to set the column width to 0 again but it doesn't works. (There will be a recursive call)
|
|
|
|
|
it doesn't have to be recursive:
if the size of the column is not 0, then resize the column
if the size of the column is 0, then exit the function
Jason
|
|
|
|
|
how can we add a icon to a subitem in the listwiew
with VB6 we can add icon to the subitems :
Function Add([Index], [Key], [Text], [Icon], [SmallIcon]) As ListItem
ListItem.ListSubItems Add([Index], [Key], [Text], [ReportIcon], [ToolTipText]) As ListSubItem
how can we replace the features of this method ??
Braham Mounir
-- modified at 6:06 Wednesday 10th May, 2006
|
|
|
|
|
Hello,
I was wondering if anyone has any ideas on how to prevent an "Change" event to be raised two or more times when monitoring a directory for file changes? I have a application that writes log information to a logfile when ever a file changes. The logfile can be hard to read when their is multiple entries of the same change.
Thank you,
|
|
|
|
|
In my application, I watch a folder for any newly created files. If a file "pops" up in the directory, any data in that file gets parsed to a database automatically. Files "pop" up in the directory from other applications using StreamWriters.
I don't really understand the FileSystemWatcher class well, but I could get my code to "trigger" only once by simply adding handlers for only the .Changed event of the watcher (and not the .Created, .Deleted, .Renamed, etc events).
For my watcher (mw), I would set the .NotifyFilter property and enable events:
mw.NotifyFilter=NotifyFilters.Attributes Or NotifyFilters.LastWrite
mw.EnableRaisingEvents
and use only a single handler:
AddHandler mw.Changed, AddressOf FolderChanged
When files show up in the watched directory, the FolderChanged subroutine triggers only once, gets the newly added file, and parses the contents to a database.
This seems to work well if the files are created as Streams from other applications. It doesn't work though, if I manually drag/drop a file into the watched directory,..this seems to create two "changed" events which results in the FolderChanged subroutine being called twice resulting in two records being created in the db.
But then,..my app doesn't require manual drag/drops,..so for me, it does the job.
So, to make a long winded story short,..I could get the .change event of the watcher to trigger once when I used only a single handler in my particular app. Don't add any additional handlers. Probably obvious to most....so this may not help you.
I'm gonna watch this post as I too am interested in being able to better define what events in a directory can trigger the FileSystemWatcher object. I don't understand this bitwise "ORing" process doesn't seem to have enough options for fine-tuning events.
Good Luck
Dave
|
|
|
|
|
DSAlbin,
Thank you for responding to my question.
I find tuned my System.IO.FileSystemWatcher code to only watch for changes. I notice I had to set my notifyfilter to NotifyFilters.LastAccess instead of NotifyFilters.Attributes. The watch responded with only two entries in a random order (could be ten passes before the watch responds twice or the watch could respond with two entries one after another), otherwise it responded once like you said. I can live with this, but you are right the FileSystemWatcher is hard to control and I too still do not fully understand it.
I still can not find a VB.NET author that fully explains the System.IO.FileSystemWatcher class.
Again, thank you for your response.
Dave
|
|
|
|
|
Hi Dave (that's my name too )
I found a nice program at this link: "http://abstractvb.com/code.asp?A=1081" by someone named Jayesh Jain where I thought his coding technique was useful.
I agree very much with you that the FSW class is not very well documented, particularly in how various combinations of "OR" statements can be expected to behave when messing around with files.
In Jain's code, he uses a combination of "ORing" the .DirectoryName, .Filename, and finally the .Attributes enumerators to define his .NotifyFilter property, e.g.:
mw.NotifyFilter = NotifyFilters.DirectoryName
mw.NotifyFilter = mw.NotifyFilter Or NotifyFilters.FileName
mw.NotifyFilter = mw.NotifyFilter Or NotifyFilters.Attributes
(where mw is an instance of FileSystemWatcher)
he then defines the following handlers:
AddHandler mw.Changed, AddressOf logchange
AddHandler mw.Created, AddressOf logchange
AddHandler mw.Deleted, AddressOf logchange
AddHandler mw.Renamed, AddressOf logrename
and then the following routines (the .Renamed event passes a different signature and thus needs it's own subroutine):
Private Sub logchange(ByVal source As Object, ByVal e As _
System.IO.FileSystemEventArgs)
If e.ChangeType = IO.WatcherChangeTypes.Changed Then
txt_folderactivity.Text &= "File " & e.Name & _
" has been changed" & vbCrLf
End If
If e.ChangeType = IO.WatcherChangeTypes.Created Then
txt_folderactivity.Text &= "File " & e.Name & _
" has been created" & vbCrLf
End If
If e.ChangeType = IO.WatcherChangeTypes.Deleted Then
txt_folderactivity.Text &= "File " & e.Name & _
" has been deleted" & vbCrLf
End If
End Sub
Public Sub logrename(ByVal source As Object, ByVal e As System.IO.RenamedEventArgs)
txt_folderactivity.Text &= "File" & e.OldName & " has been renamed to " & e.Name & vbCrLf
End Sub
I played with this a little, and came up with this logic table:
1) Files streamed into a folder will trigger both the .changed and .created events
2) Files streamed over an already existing files will trigger (2) .changed events
3) Files that are deleted will trigger only the .deleted event
4) Files that have their names changed will trigger both the .renamed and .changed events
5) Files that are dragged/droped into the folder will trigger both a .created and .changed event
6) Files that are created within the folder by right-clicking-->Add new, will trigger only the .created event
7) Files that exist within the directory and are dragged out of it will trigger a .deleted event
8) Opening, editing, and saving changes to a file will trigger (2) .changed events
As you can see, many of these actions will only trigger the .changed event once (1, 4, and 5),...so if place your "log to file" code in the "e.ChangeType = IO.WatcherChangeTypes.Changed" If-then statement above, you should only get (1) entry.
Anyway, that's how I use this class,..just play with it until the actions you expect only cause a single .change event to trigger,..
oh well,...not as "clean" an approach as i'd prefer,.but hopefully it'll work for you!!
-Dave
Dave
|
|
|
|
|
Dave,
Thanks for getting back with me. Much appreciated.
Anyway. I must of read an article similar to Jayesh Jain on another interent site before because I had been also playing with simialar example.
Anyway, Jain code works the sameway with the "Change Events" you are correct about limiting the number of "Notifyfilters" to use. I disagree on how Jain uses the following example set for the filter.
wf.NotifyFilter = wf.NotifyFilter Or IO.NotifyFilters.FileName
wf.NotifyFilter = wf.NotifyFilter Or IO.NotifyFilters.Attributes
These statements cause the "FileSystemWatcher" to change more then once for a single change on the file.
Instead use this ....
wf.NotifyFilter = IO.NotifyFilters.FileName
wf.NotifyFilter = IO.NotifyFilters.Attributes
Also, the programmer needs to decide what kind of event to watch for ie. "Change" or "Created". I would not use both for the same "FileSystemWatcher" class.
I used the "wf.NotifyFilter = IO.NotifyFilters.LastAccess" instead of Jain's example because it still detect the events without the "change" events occuring mupliple times.
Keep intouch and I will continue to look for your comments.
Below is what I had came up with...
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
wf = New System.IO.FileSystemWatcher
On Error Resume Next
wf.Path = Me.txtWatchPath.Text
wf.Filter = Me.txtBoxFilter.Text
wf.NotifyFilter = IO.NotifyFilters.LastAccess Or IO.NotifyFilters.FileName
' add the handler to each event
AddHandler wf.Changed, AddressOf logChange
' add the rename handler as the signature is different
AddHandler wf.Renamed, AddressOf logRename
AddHandler wf.Error, AddressOf errorlogChange
On Error Resume Next
If Me.chkWatchsubDirecties.Checked = True Then
wf.IncludeSubdirectories = True
Else
wf.IncludeSubdirectories = False
End If
wf.EnableRaisingEvents = True
Me.btnStart.Enabled = False
Me.btnStop.Enabled = True
Me.txtBoxFilter.ReadOnly = True
' Turn off the update of the display on the click of the control.
Me.chkWatchsubDirecties.AutoCheck = False
End Sub
Private Sub errorlogChange(ByVal source As Object, ByVal e As ErrorEventArgs)
Dim sMessages As String
' Show that an error has been detected.
If TypeOf e.GetException Is InternalBufferOverflowException Then
Me.txtFolderActivity.Text &= ( _
"The file system watcher experienced an internal buffer overflow: " _
+ e.GetException.Message)
End If
End Sub
Private Sub logChange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
If e.ChangeType = IO.WatcherChangeTypes.Changed Then
' Specify what is done when a file is changed, created, or deleted.
Me.txtFolderActivity.Text &= "File name is: " + e.FullPath & " has been changed" & _
" @" & TimeString & ControlChars.NewLine
End If
'If e.ChangeType = WatcherChangeTypes.Created Then
' Me.txtFolderActivity.Text &= "File name is: " + e.FullPath & " has been created" & ControlChars.NewLine
'End If
'If e.ChangeType = WatcherChangeTypes.Deleted Then
' Me.txtFolderActivity.Text &= "File name is: " + e.FullPath & " has been deleted" & ControlChars.NewLine
'End If
End Sub
Private Sub logRename(ByVal source As Object, ByVal e As System.IO.RenamedEventArgs)
Me.txtFolderActivity.Text &= ("File: " & e.OldName & " has been renamed to: " & e.Name & " " & ControlChars.NewLine)
End Sub
Dave
|
|
|
|
|
Hi again Dave,
Here's another way to define the .NotifyFilters property that performs well:
wf.NotifyFilter = 0
wf.NotifyFilter = mw.NotifyFilter Or NotifyFilters.FileName
It handles calling the wf.created, wf.deleted, wf.changed, and wf.renamed events in a surprisinly logical way. Here is the action - logic table:
Action: Triggers
drag/drop a file into the watched directory wf.Created
drag/drop a file onto an existing file in the directory wf.Deleted and wf.Created
drag a file out of the watched directory wf.Deleted
stream a file into the watched directory wf.Created
copy and paste a file into the watched directory wf.Created
Right-click and "Delete" a file in the directory wf.Deleted
Your suggestion of just using wf.NotifyFilter= IO.NotifyFilters.LastAccess also gives single event triggers but doesn't trigger for some actions.
Action: Triggers
drag/drop a file into the watched directory wf.Changed
drag/drop a file onto an existing file in the directory wf.Changed
drag a file out of the watched directory <no triggers="">
stream a file into the watched directory wf.Changed
copy and paste a file into the watched directory <no triggers="">
Right-click and "Delete" a file in the directory <no triggers="">
I didn't care much for the combination of IO.NotifyFilters.LastAccess OR IO.NotifyFilters.Filename as the logic table yielded too many "multiple" events:
Action: Triggers
drag/drop a file into the watched directory wf.Created then wf.Changed
drag/drop a file onto an existing file in the directory wf.Deleted then wf.Created then wf.Changed
drag a file out of the watched directory wf.Deleted
stream a file into the watched directory wf.Created
copy and paste a file into the watched directory wf.Created
Right-click and "Delete" a file in the directory wf.Deleted
Well,...at this point,..I'm feeling a little better about how to use this object. Thanks for the exchange of information. It was very useful!
-Dave 
|
|
|
|
|
Does anyone have an example on how I can populate a DataGrid using an ADO connection?
Thank you,
Quecumber256
|
|
|
|
|
Hi, i create a menu from a database using datareader
then i 'm adding a handler for click event.
now iwant inside the handler procedure to get the text of the menuitem who called the handler and that's exactly my problem.
this is my code
Public Sub devsubmenu()
Dim cmddev As New OleDbCommand("Select modelname from devicetbl",OleDbConnection1)
OleDbConnection1.Open()
Dim dtread As OleDbDataReader = cmddev.ExecuteReader()
devmnu.MenuItems.Clear()
Do While dtread.Read
Dim ChildMenu As New MenuItem
ChildMenu.Text = dtread.Item("modelname").ToString()
AddHandler ChildMenu.Click, AddressOf model_click
devmnu.MenuItems.Add(ChildMenu)
Loop
OleDbConnection1.Close()
End Sub
End Sub
Private Sub model_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' HERE I WANT TO TAKE THE MENUITEM (SENDER) TEXT AND PUT IT IN A TEXT BOX
End Sub
any ideas ?
|
|
|
|
|
I've got a very weird problem, when I run the following code the
ComboBox (Me.cmbInputDevice) is always empty. The ComboBox is on a
UserControl in a Class Library. I'm using VS.NET 2003 with SourceSafe
6.0d (the problem occurs whether the code is checked in or out)
If I step through the code, The line
Me.cmbInputDevice.DataSource = dv
Executes fine (ie, doesn't error), but on the next line (after an
F8/F11) Me.cmbInputDevice.DataSource is still equal to Nothing.
dv is definately not Nothing, and is definately not empty (I can view
it's contents in the Command Window)
*if* I delete the combo box from the control, and add a new one, give it
the same name, etc, it works for a while, but then goes back to
not-working after an unknown period. This isn't any kind of practical
solution.
Sql.GetDeviceTable() returns a valid & populated DataTable
[VB.NET] (Native Language)
Dim dt As DataTable = Sql.GetDeviceTable()
Dim dr As DataRow = dt.NewRow()
dr("ID") = DBNull.Value
dr("Description") = "<none>"
dt.Rows.Add(dr)
Dim dv As DataView = dt.DefaultView
dv.Sort = "Description"
dv.ApplyDefaultSort = True
Me.cmbInputDevice.DataSource = dv
Me.cmbInputDevice.DisplayMember = "Description"
Me.cmbInputDevice.ValueMember = "ID"
[C#] (Translation)
DataTable dt = Sql.GetDeviceTable();
DataRow dr = dt.NewRow();
dr("ID") = DBNull.Value;
dr("Description") = "<none>";
dt.Rows.Add(dr);
DataView dv = dt.DefaultView;
dv.Sort = "Description";
dv.ApplyDefaultSort = True;
this.cmbInputDevice.DataSource = dv;
this.cmbInputDevice.DisplayMember = "Description";
this.cmbInputDevice.ValueMember = "ID";
Hiren
-- modified at 14:04 Tuesday 9th May, 2006
|
|
|
|
|
Just make shorting property false.
this.cmbInputDevice.Sorted=False
IT works.....
etettr
|
|
|
|
|
Dear friends,
I have one VB form with two picture boxes on it. I have a picture in of the picture box and the other is empty. How can I cut the part of the picture inside the first picture box and paste that in the the second picture box. How can I pass the dimension from where to where I need to cut the picture. Please help me out in this matter. I really need to cut picture in lots of pieces and put them in seperate picture boxes for some special purpose.
Your quick response will be highly appreciated.
Thanks and Regards
Murtuza Patel
|
|
|
|
|
The easiest way is to not use the picture box control. If you handle your apps 'paint' event and draw the bitmap yourself, you can draw the parts where-ever you like, without having to actually chop up your source bitmap into lots of bitmaps.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
I've been banging my head on the keyboard for a few days now searching for a solution to my problem. Iv'e searched Google for a solution but I can't seem to find any.
The node information is stored in a MySQL database using the nodes.fullpath command or like this:
lvl1\lvl2\lvl3
Now, I've seen and tried to use the treeview.nodes.add(1).nodes.add(2).nodes.add(3) with a split command but because I don't know how many levels there are before hand this makes a giant select case that makes me cry each time I see it.
I want the routine to check if the level exists then add it if it doesn't and/or move to the next level. (Geez it sounds so simple writen like that...)
Here is the routine I'm using
Dim SQL As String = "Select * from troubleshooting order by node_path asc"<br />
Dim StrNodePath As String<br />
Dim nNode As TreeNode<br />
Dim BolNew As Boolean = True<br />
Dim X As Integer<br />
Dim StrNode As String<br />
<br />
<br />
RSProbleme = ReturnForm.StrConn.Execute(SQL)<br />
<br />
Do Until RSProbleme.EOF = True<br />
<br />
StrNodePath = RSProbleme("node_path").Value<br />
aNodePath = Split(StrNodePath, "\")<br />
<br />
For X = 0 To UBound(aNodePath)<br />
BolNew = True<br />
For Each nNode In TrVProbleme.Nodes<br />
<br />
If nNode.Text = aNodePath(X) Then<br />
BolNew = False<br />
End If<br />
<br />
Next<br />
If BolNew = True Then<br />
nNode.Nodes.Add(aNodePath(X)) <-- This is the line that gives me trouble<br />
End If<br />
Next<br />
<br />
RSProbleme.MoveNext()<br />
Loop
When adding it gives me the error, "Object reference not set to an instance of an object." and using the variable watch in VS it says that nNode = Nothing.
Any help will be greatly appreciated. (My head hurts from all that banging...)
Thanks
For every action there is an equal and opposite malfunction
|
|
|
|
|
I am guessing that you created a treeview called TrVProbleme in your application. If you have not added any nodes to the treeview - then nNode will be nothing. You might want to try changeing the statement nNode.Nodes.Add(aNodePath(X)) to TrVProbleme.Nodes.Add(aNodePath(X))
Hope this helps
Digicd1
|
|
|
|
|
Indeed you are correct; while I did not change the line as you suggested I've added a If... End If checking if this was a root node or not then added your line.
(Can't believe it was so simple grr...)
Thanks a bunch!
Raist
For every action there is an equal and opposite malfunction
-- modified at 12:12 Wednesday 10th May, 2006
|
|
|
|
|
hi!
have u finish adding nodes to a treeview control?
can u help me!
can u give me ur code and the code in SQL!
i need it badly!
i hope u can help me!
thanks a lot!
coder
|
|
|
|
|
What kind of code are you interested in and what is the purpose?(what is it supposed to do?)
Raist
For every action there is an equal and opposite malfunction
|
|
|
|
|
good morning! a code that will retrieve the data from database or using query!
i will use the treeview for making a organizational chart!
one main ParentNode(Division),childnode(Department) and subchildnode(Section)
Thanks for ur kindheart!
"Giving something does not reduce what you have but gain more!"
coder
|
|
|
|
|
Good morning!The code that i will use is all that name in the node that wiil display is came from the database,
or using query!
i will use it in making organizational chart!
the content is i have a parentnode(Division), Chilnode(Department) and SubChildnode(Section).
thanks!
" Giving something to anyone is not reducing what u have instead you gain more!"
coder
|
|
|
|
|
Hi!
The following code selects a row from a table. If the row exists then it is updated otherwise a new row is added to the table.
How can I write this code using ADO.NET 2.0?
Dim rsRequest As New ADODB.Recordset<br />
rsRequest.Open "Select Form_No, User_ID, Status, Request_Date from tbl_ReExport_Info Where Form_No = '" & txtFormNo.Text & "' And User_ID = '" & txtUserID.Text & "'", cnnADO, adOpenDynamic, adLockOptimistic<br />
With rsRequest<br />
If .EOF = True Then .AddNew<br />
!Form_No = txtFormNo.Text<br />
!User_ID = txtUserID.Text<br />
!Status = 0<br />
!Request_Date = Now<br />
.Update<br />
End With<br />
Thank You
Gulfraz Khan
|
|
|
|
|