|
Ok, I'm having a bit of trouble understanding what you're saying here...
Try setting some breakpoints, and see where the code is going. Put a breakpoint on the RaiseEvent statement (If it doesn't get to there, you've done something wrong in your code)... From there, it should jump straight to the SetSearchedDs routine. If not, set a breakpoint at the AddHandler and make sure it's hitting that.
And if you're using an On Error Resume Next (*shudder*), shut it off, or you'll never find the problem
Oh, and you're mixing the two ideas... Either use (Me.Parent as MainForm) method OR the RaiseEvent... The event is more standard.
|
|
|
|
|
Thanks Ian,
I wasn't using OnError (I love Error Handling) not using both Me.Parent & RaiseEvent, but was trying to see which is working & how. While working with Raise.. Me.parent was commented. BUT the problem was a third thing only.
I had copied my full folder to another comp & was working on it. The paths incliding the drives for both pcs r different. That was not making the files avbl to the compiler. I added breakpoints, & got msg (while debugging) that the file location is changed from original version. I selected Location->Allow......, but that still didn't worked) Can you please tell me how to work out in this scenario with 2 diff. pcs. I work on 1 pcs, then copy the folder to other pc & start working there. But ddue to path differnce it is not working as expected. Today morning when i tried the saem thing straight away with Events, it worked as expected in the first try.
What sh i do to make it work on both pcs or how sh i copy it or set some properties etc. I am totally unaware for this kind of solution. Kindly help me.
Thanks
Terry
|
|
|
|
|
Well, that's a different problem... You've got paths hardcoded somewhere, and without knowing more about your project, I can't really offer any advice.
|
|
|
|
|
Can anybody guide me how to change textbox/combobox border color on GotFocus event.
Many thanks
Nas
|
|
|
|
|
The TextBox doesn't expose any functionality for changing its border colors. You'd have to implement your own version of the TextBox, inheriting from the current TextBox class, and override the painting code and replace it with your own. You'd also have to supply new properties to allow you to specify the border color you want.
|
|
|
|
|
Many thanks Dave.
Regards
|
|
|
|
|
Here is what I am trying to do:
1) Select some text let's say in App 1.
2) Switch to App 2, but as the switch occurs, copy the selected text from App 1 to the clipboard without the user pressing Ctrl-C.
3) Modify the text in the clip board, which I already know how to do.
4) Switch back to App 1 and automatically paste the modified text where the selected text is without the user pressing Ctrl-V.
Any ideas would be appreciated.
Thanks,
Joe C.
joe c
|
|
|
|
|
programmerwantabe wrote: 1) Select some text let's say in App 1.
2) Switch to App 2, but as the switch occurs, copy the selected text from App 1 to the clipboard without the user pressing Ctrl-C.
Are you writing this "App 1"? If not, you'll find this to be a very difficult thing to do. When you switch apps, it's too late to tell the previous app to copy it's text to the clipboard. There is also no API function to tell you which window HAD the focus when your app gets the focus. So, you have to write some hook code to track which window has the current focus, all the time. When your app finally gets the focus, you have to look at this value to get the handle of the window that HAD the focus. Then you can use that to tell the previous window to copy it's contents to the clipboard.
|
|
|
|
|
Hello David
Thank you for your reply. I agree with you, especially since I didn't write App 1 this would be a difficult task to accomplish.
Regards,
Joe C.
joe c
|
|
|
|
|
I am getting this error when I run my program. My program fills a datagrid on using a timer to fill it every so many seconds. That works fine. I have a System watcher program that watches for changes in a database. At that time I want the same datagrid filled again. I have put the fill into a method:
Me.TransactionTableTableAdapter.Fill(Me.MyTestDataSet.TransactionTable)
Me.newDataGrid.Refresh()
When the watcher method calls the fill method it gives me the error Cross-thread operation not valid: Control 'newDataGrid' accessed from a thread other than the thread it was created on.
I researched Google and didn't find anything helpful. Does anyone know a better way of doing it?
|
|
|
|
|
Hi Cory,
this gets covered here and everywhere at least once a week.
As usual, it suffices to search for part of your message, say
"accessed from a thread other than the thread it was created on"
(so DONT include the specific "'newDataGrid" since that's your naming).
Microsoft gives a good "SetText" example.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
OK.. I read up on this and am still having trouble. There are some things I am unclear on.
I create a Delegate class variable
Delegate Sub callDel()
My program calls
Private Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
I create an instance
Dim del As callDel
Then
del = New callDel(AddressOf UpdateGrid)
I can't call UpdateGrid()
so I try
del.Invoke()
It doesn't work. UpdateGrid is suppose to fill my datagrid and doesn't.
What am I doing wrong? Again, my timerclock calls the same Updategrid method and works.
|
|
|
|
|
Hi Cory,
please show the complete method that contains the Invoke and InvokeRequired stuff,
plus some more if necessary. I can't figure it out from 5 separate lines you know.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
This is where I want to call the method that updates the grid.
<code> Private Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
If firstTruck = True Then
updateTimer.Stop()
del = New callDel(AddressOf UpdateGrid)
del.Invoke()
del = New callDel(AddressOf UpdateList)
del.Invoke()
updateTimer.Start()
firstTruck = False
End If
</code>
This is the method that updates correctly in my timer but not in the OnChanged event.
Public Sub UpdateGrid()
If display = "All Trucks" Then
Me.TransactionTableTableAdapter.Fill(Me.MyTestDataSet.TransactionTable)
Else
Me.TransactionTableTableAdapter.FillBy(Me.MyTestDataSet.TransactionTable)
End If
' Me.newDataGrid.Refresh()
End Sub
|
|
|
|
|
Hi,
a thread is not allowed to touch a Control it did not create.
Since normally all controls are in some relation to each other, and the
first Control (your main form) is created by the first, main or "GUI" thread,
only the GUI thread can access each and every one of your controls.
Additional threads are not allowed to touch existing controls, hence they
must use InvokeRequired and Invoke, as in all the examples.
This method is part of a form class, so Me is a Form (hence a Control):
Private Sub SetText(ByVal [text] As String)
' InvokeRequired required compares the thread ID of the
' calling thread to the thread ID of the creating thread.
' If these threads are different, it returns true.
If Me.textBox1.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {[text]})
Else
Me.textBox1.Text = [text]
End If
End Sub
The Invoke applies to the control that needs being accessed, NOT to
some delegate. How would the delegate know where to send the message ?
Only the Control knows its creator, and whether Invoke is Required.
Study the examples !
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
It is working thank you.
-- modified at 10:33 Thursday 30th August, 2007
|
|
|
|
|
I am working on a vb.net program that will search the directory for files. Currently, I search for files with a specific ext by entering the ext in textbox. Now, I want to be able to search the directory for the ext from a database tbl instead of entering the extensions into a textbox. I have a tbl in access called tblRestrFileExtension which has the following columns:
ExtID
(AutoNumber)
ExtType:
.wmv;.wav;.mp3;.exe
Here is my project code:
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click<br />
lblStatus.Text = "Scanning Please Wait....."<br />
Application.DoEvents()<br />
Dim enteredFilePaths As String() = My.Settings.Path.Split(New String() {";"}, StringSplitOptions.RemoveEmptyEntries)<br />
Dim patterns As String() = TextBox2.Text.Split(New String() {";"}, StringSplitOptions.RemoveEmptyEntries)<br />
<br />
'Declare a string array to store the file paths that are not found in the database<br />
Dim dv As DataView = dt.DefaultView<br />
Dim i As Integer<br />
<br />
For Each path As String In enteredFilePaths<br />
Dim strFilter As String = "ExcludePath LIKE '" & path & "%' AND (ExcludeFileName LIKE '%" & patterns(0) & "'"<br />
For int As Integer = 1 To patterns.GetUpperBound(0)<br />
strFilter += " OR ExcludeFileName LIKE '%" & patterns(int) & "'"<br />
Next<br />
strFilter += ")"<br />
dv.RowFilter = strFilter<br />
dv.Sort = "ExcludePath ASC"<br />
For i = 0 To dv.Count - 1<br />
Me.ListBox2.Items.Add(dv(i)("ExcludeFileName"))<br />
Next i<br />
Next<br />
<br />
Dim fileName As String<br />
patterns = Array.ConvertAll(patterns, New Converter(Of String, String)(AddressOf ConvertFilters))<br />
ListBox1.BeginUpdate()<br />
ListBox1.Items.Clear()<br />
Dim RootDirs As New List(Of String)<br />
'Check to see if there there are any Root Directory path in Textbox1 string<br />
For idx As Integer = 0 To enteredFilePaths.Length - 1<br />
'Bypass the drive letter so that any drive can be used<br />
If enteredFilePaths(idx).Substring(1).Trim = ":\" Then<br />
'Get all the root folders<br />
Dim RootFolders As New System.IO.DirectoryInfo(enteredFilePaths(idx))<br />
'Add all the foilers to the RootDirs array list<br />
For Each dir As System.IO.DirectoryInfo In RootFolders.GetDirectories()<br />
RootDirs.Add(dir.FullName)<br />
Next<br />
'Continue at the top of the For loop so that we do not add the root path back into the list<br />
Continue For<br />
End If<br />
'The path was not a root folder so add it to the list<br />
RootDirs.Add(enteredFilePaths(idx))<br />
Next<br />
'Resize your string array to the size needed to add the new paths<br />
ReDim enteredFilePaths(RootDirs.Count - 1)<br />
'Copy the RootDirs List of path to the folders array.<br />
RootDirs.CopyTo(enteredFilePaths)<br />
For Each folder As String In enteredFilePaths<br />
Try<br />
For Each file As String In My.Computer.FileSystem.GetFiles(folder, FileIO.SearchOption.SearchAllSubDirectories, patterns)<br />
fileName = System.IO.Path.GetFileName(file).ToLower<br />
If ListBox2.FindStringExact(fileName) = -1 Then<br />
ListBox1.Items.Add(fileName)<br />
End If<br />
Next<br />
Catch ex As UnauthorizedAccessException<br />
End Try<br />
Next<br />
ListBox1.EndUpdate()<br />
lblStatus.Text = "Scan Complete!!!"<br />
End Sub<br />
<br />
Private Function ConvertFilters(ByVal filter As String) As String<br />
Return "*." & filter<br />
End Function<br />
<br />
Public Function GetConnectionString() As String<br />
'Create a datatable to store data.<br />
dt = New DataTable("tblExclude")<br />
Dim colExFileID As New DataColumn("ExcludeID")<br />
Dim colExFilePath As New DataColumn("ExcludePath")<br />
Dim colExFileName As New DataColumn("ExcludeFileName")<br />
dt.Columns.AddRange(New DataColumn() {colExFileID, colExFilePath, colExFileName})<br />
Dim myconnString As String = My.Settings.ConnectionString<br />
'Replace the {0} with the value from StartUpPath.<br />
Dim myConnection As New OleDbConnection(myconnString)<br />
Dim strSQL As String = "SELECT * FROM tblExclude"<br />
Dim dAdapter As New OleDbDataAdapter()<br />
Return String.Format(myconnString, Path.Combine(Application.StartupPath, "File.mdb"))<br />
myConnection.Open()<br />
dAdapter.SelectCommand = New OleDbCommand(strSQL, myConnection)<br />
dAdapter.Fill(dt)<br />
myConnection.Close()<br />
End Function<br />
<br />
Private Sub SearchFileForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
GetConnectionString()<br />
End Sub
Thanks
jds1207
|
|
|
|
|
OK. You've got a huge spaghetti problem here. For example, just look at the single line of code in your Form's Load event handler.
GetConnectionString()
Now, I'm all for self-documenting code and the name you chose for this method is pretty decent, but I would expect a method with that name to actually return a connection string. Your GetConnectionString method does everything BUT return a connection string! Why do you have a method with this name creating a DataTable, creating columns in it, opening a connection, executing an SQL command, filling that DataTable, and NOT returning a connection string?
You have this problem throughout this bowl of noodles you call code and it's this very problem that's causing your issues now that you want to change one little piece of functionality.
This stuff should be broken down into more methods, seperating and encapsulating functionality. You got the first method name correct, GetConnectionString . Now make it actually return a connection string!
Public Class DatabaseLayer
Private Shared Function GetConnectionString(ByVal filename As String) As String
' Build the full path to the specified database file and see if this
' file exists
Dim fullPath As String = Path.Combine(Application.StartupPath, filename)
If Not File.Exists(fullPath) Then
Throw New FileNotFoundException("Unable to locate the database file {0} in the application folder.")
End If
' Get the connection string template
Dim connStringTemplate As String = My.Settings.ConnectionString
' Build and return the completed connection string
Return String.Format(connStringTemplate, Path.Combine(Application.StartupPath, filename))
End Function
Private Shared Function CreateDatabaseConnection(ByVal filename As String) As OleDbConnection
' Get a connection string for the specified database file
Dim connString As String = GetConnectionString(filename)
' Return an OleDbConnection object
Return New OleDbConnect(connString)
End Function
Private Shared Function GetFileExcludeTableSelectCommand() As OleDbCommand
Dim selectSql As String = "SELECT " & _
"ExcludeID, ExcludePath, ExcludeFileName FROM tblExclude"
Return New OleDbCommand(selectSql)
End Function
Private Shared Function CreateFileExcludeTableDataAdapter(ByVal selectCommand As OleDbCommand, ByVal connection As OleDbConnection) As OleDbDataAdatper
Dim da As New OleDbDataAdapter(comm, conn)
' Put code here to add any command parameters and use the OleDbCommandBuilder
' to finish building the DataAdpters UPDATE, DELETE, and INSERT commands.
Return da
End Function
Public Shared Function GetFileExcludeTable() As DataTable
Dim dt As New DataTable("FileExcludeTable")
Dim conn As OleDbConnection = CreateDatabaseConnection("File.mdb")
Dim comm As OleDbCommand = GetFileExcludeTableSelectCommand()
Using da As OleDbDataAdapter = CreateFileExcludeTableDataAdapter(comm, conn)
da.Fill(dt)
End Using
Return dt
End Function
This is just a small SAMPLE of a data layer, meant to demonstrate encapsulation and modularization.
|
|
|
|
|
Ok, this is very helpful but it still does not solve the problem.
Database Table
ExtID
(AutoNumber)
ExtType:
.wmv;.wav;.mp3;.exe
Currently my program search for file extensions by entering the extension into a textbox, for example wav;mp3;exe. Whatever extension is typed into textbox the program will look for those extensions. How can I search for specific file extensions from the ExtType column in database istead of entering the ext in the textbox? I have the field where all of the extensions are in one column.
|
|
|
|
|
jds1207 wrote: this is very helpful but it still does not solve the problem.
Wanna bet??
The problem you're running into is that all of this code is attached to a button event handler. You have to break this code out so it's not dependant on the UI click events at all. The code needs to be refactored to seperate the functionality from that TextBox. The search function needs to be able to stand on its own and do it's job just by passing the extensions to a method to start the search. Once you seperate this search code from the UI, your problem is 95% solved.
|
|
|
|
|
How To use a component that is present outside the current working environment.
How deos the DataAdpter,DataSet work together in establishing connection between VB.NET and SqlServer2005.Explain with example
trustworthy
|
|
|
|
|
somunu wrote: How To use a component that is present outside the current working environment.
No idea what you mean
somunu wrote: How deos the DataAdpter,DataSet work together in establishing connection between VB.NET and SqlServer2005.Explain with example
ADO.NET works in a very simple and well defined way - some classes handle connecting to the DB, others handle creating a representation of the data returned. Have you got any books on the topic ? Have you tried google ?
What you're asking is not clear, in both cases.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hi All
i want to Deploy my application, am using Access as my backend.i have included the DB with the application. but now when i install it on a client's machine it reqiures a Database to be in
C:Programfiles\Development For One\Search_Property
How do i Deploy my Application, when it is being installed on a client machine, it should have the correct mappings?
PLease provide Articles or Explanation.
Thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding
|
|
|
|
|
Vuyiswamb wrote: it should have the correct mappings?
What do you expect the "correct mappings" to be?? Where did you want the database to be?? What does the code look like that builds the file path to the database?? Or did you make the mistake of hard-coding the path to the database into your application??
|
|
|
|
|
Dave Kreskowiak wrote:
|What do you expect the "correct mappings" to be??
When i install it in a client machine, it will go to c:\Programfiles\MYApp\mydb.mdb. but now it is looking for that DB in same location where i was Developing. what if i was Developing this application and Saved all my Projects under a different Drive like G:,when i install it in my client machine it will look for a the db in G: drive.
Dave Kreskowiak wrote:
Where did you want the database to be??
i want it to be in the Application Folder, yes i can achieve that, but now, even if i put it in the application folder, it will still look for in my Development drive. i have used a wizard to make a connection to my database and the Db is in my application development directory.
Dave Kreskowiak wrote:
What does the code look like that builds the file path to the database??
i used a Wizard to achieve this, so i did not hardcode the DB mappings
Thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding
|
|
|
|
|