|
OK. What are you trying to do with this?
Are you just trying to clear a form from a seperate class?? If so, then it's bad practice to do it from your class. If your class knew anything about the form it's trying to modify, it would then be permanently tied to that form and not be able to be reused somewhere else.
What you should be doing is sending back data to the form that it knows should signal that some processing is done. This signal can then be used as a trigger so the form clears its own textbox's. This is either done with a return value from your class' method, or from an event or callback delegate that your form subscribes to.
With this model, your class can be reused with any UI, be it a Compact Framework app, ASP.NET app, Web Service, ...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks for the response Dave
Dave Kreskowiak wrote: an event or callback delegate that your form subscribes to
I've been trying to work with the delegate again all morning, and i'm just missing the connection (in my brain) somewhere. Heres what I have...
Form1(Modify2.vb)
Create the delegate:
Public Delegate Sub ClearDel(ByVal clear As Boolean)
Create the event:
Private evtClear As ClearDel
Public Sub Register(ByVal objClear As ClearDel)
'raise event here?
End Sub
Public Sub fireClear()
'clearing code
End Sub
Form2(frmPayableInfo)
Private WithEvents mobjModify2 As Modify2
In the sub where I process, at the end i have this:
mobjModify2 = New Modify2
mobjModify2.Register(New Modify2.ClearDel(AddressOf eventClear)
and then i have the sub:
Public Sub eventClear(ByVal clear As Boolean)
clear = True
End Sub
So now the question is, how do I hook up the fireClear() event on Form1(modify2.vb) with the delegate. And where would I set the condition for the delegate to fire? Thanks again for the response.
Nathan Lindley
.NET Aficionado
|
|
|
|
|
Wow! You've got everything backwards and in the wrong classes.
First of all, get off the delegate kick and start explaining what you're trying to do. Since you're using two forms, the circumstances have now changed.
Does Form1 show Form2 as a dialog and wait for the user to close Form2? If so, then all you have to do in Form2 is expose the data as a few properties and resume execution from after the ShowDialog call:
' In Form1
Dim myForm2 As New Form2()
' ShowDialog is a blocking call, so nothing after it will execute
' until the dialog is dismissed by the user.
If myForm2.ShowDialog() = DialogResult.OK Then
' Get the data off of Form2 and do something it...
Dim x As Integer = myForm2.someProperty
' Clear the textbox controls...
ClearMyControls()
End If
' When using ShowDialog(), you MUST call Dispose on the object
' when you're done with it!
myForm2.Dispose()
Now, if you're running both forms simultaneously, you can expose some events in Form2 that Form1 can subscribe to:
' In Form2
Public Event SomethingHappened(ByVal someValue As Integer)
Public Sub SomeMethod()
' Do something then raise an event to say it was done.
RaiseEvent SomethingHappened(data)
End Sub
' In Form1
Dim myForm2 As New Form2()
AddHandler myForm2.SomethingHappened, AddressOf MyHandler
.
.
' Must match the signature of the SomethingHappened event!
Private Sub MyHandler(ByVal value As Integer)
' We were told something happened. Clear our controls!
ClearMyControls()
End Sub
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks for the response Dave K
Like I said I am brand new to the whole delegate concept so I have no idea how they work. First let me just explain my situation. I have a form that displays a datagrid with customer info. when you double click the start of the row, it opens up a form (form2) that has a bunch of information based on the record that was clicked. When I submit this information (form2) I need to clear the datagrid (on form1) so that the user has to look up the ID of the person they updated (i probably should just reset the find, but thats another issue i can handle when i get this cross form communicating going), so there isn't old data. Okay. Now in your example:
Dave Kreskowiak wrote: ' In Form2
Public Event SomethingHappened(ByVal someValue As Integer)
Public Sub SomeMethod()
' Do something then raise an event to say it was done.
RaiseEvent SomethingHappened(data)
End Sub
What significance does the Integer in the argument have?
Nathan Lindley
|
|
|
|
|
nlindley7 wrote: What significance does the Integer in the argument have?
Nothing. It's just an example of how to pass data in an event.
If what you're doing in your datagrid is editing the details of that record and sending them back to the database, then you would probably show this detail form with ShowDialog(). After that statement returns (the user has finsihed editing this record and it was written back to the database), you can execute the code to refresh your datagrid's datasource.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hey Dave TA ,
The datagrid displays a list of claims for each client. When an individual claim is clicked, a new form pops up that displays the details of that particular claim. When you edit/submit the details of this form (form 2), the values are submittied to a claimsDetails table. One of the details you can edit, happens to be the primary key of the claims/claimDetails tables. So the form submits data to the database that the datagrid reads from; hence needing to refresh that table. So I would assume the second example you showed is the one to follow?
Nathan Lindley
|
|
|
|
|
Actually, the best example to follow in this case would be the first one. After the details are edited in the second form, the original form has to refresh its dataset so it can display the new data. The second form doesn't need to stay up if it's not editing anything.
What I meant by "running two forms simulataneously" is that the user can switch back and forth between the forms at any time, or they are modeless. A modal form is a dialog box. You can't continue with the rest of the application unless that dialog box is dismissed (OK or Cancel).
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
How to make a WebBrowser go through a proxy server?
I think you can do it by changing the proxy-settings in Internet Explorer, but can you do it without doing that?
Greetings - mik
|
|
|
|
|
No, the WebBrowser class will only use the proxy settings setup in Internet Explorer.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Okay - how to set the proxy-settings in Internet Explorer then
And is it possible to use another control (like a downloaded) almost like WebBrowser with the ability of using proxy?
Thanks
|
|
|
|
|
I don't know of any 3rd party controls for this.
The WebProxy class in the .NET Framework 2.0 will NOT modify the system proxy settings. It will return a COPY of them though, which you can then modify for use in your own app. Don't get any cute ideas. The WebProxy class does NOT work with the WebBrowser class. It will only work with classes that are derived from the WebRequestclass, like HttpRequest.
You can either modify Internet Explorers proxy settings through the WinHttp API function WinHttpSetDefaultProxyConfiguration[^]. I do NOT recommend doing this, since it changes the proxy settings system wide!! ANY browser window that is open will have these new settings applied to it!!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I have a couple of data tables that need to be integral to my project. While creating the project I read and write them from SQL databases. I'm worried that when I deploy the project the tables will be potentially unavailable to the user. Is there a preferred way to make the tables an integral part of the project itself? All editing of the tables is done through the project.
tias
|
|
|
|
|
If you're reading/writing this data to SQL Server, you could ship SQL Express with your app and keep the data in that. You wouldn't have to change very much code to keep it working. You're only other option is to save the data in local files, probably XML files or an Access database. But this option would require rewriting more of your code.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks Dave.
XML seems like a good option for me, but I cannot find information on how to bind an XML file to a datagrid. Can you or anyone help?
Thanks again!
|
|
|
|
|
You don't. You bind it to a DataSet just like you do now with reading the data from SQL. The only difference is you use the DataSet class' ReadXml method to get the data. This is just one of the .ReadXml()[^] method overloads:
Dim newDataSet As New DataSet
newDataSet.ReadXml(filepath)
To save it back out, it's just as easy:
newDataSet.WriteXml(filepath, XmlWriteMode.WriteSchema)
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Thanks again!
Sorry to be a pain, but can you help me with the translation? I'm used to using SQL datasets that have tables:
TickersTableAdapter.Fill(Me.DataSet1.Tickers)
TickersTableAdapter.Update(Me.DataSet1.Tickers)
DataSet1.Tables("Tickers").Select(TDataToGet)
Etc.
Following your instructions, I can read the xml dataset file from disk:
Dim TickersDataSet As New DataSet
TickersDataSet.ReadXml("c:\tickers.xml")
But then how to I get it into a format that I can operate on? Can I make that .xml dataset have tables?
|
|
|
|
|
cstrader232 wrote: Can I make that .xml dataset have tables
Yes. You have to define the .XSD files (XML Schema) which will define the tables and their fields.
The code you posted is VB.NET 2005 code. The two TableAdapter statements just retrieve data from an SQL table and places it in a DataSet object, and writes any changes back to the source table.
Which version of VB.NET are you using?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I'm using vb.net 2005 -- the freeware. Right, what I need to try to do is to treat the .xml file the same way I've been treating the sql file. The idea is to avoid the connection string, and potential problems that could occur with it during deployment. My tables are not at all big.
thank you!
|
|
|
|
|
OK, thanks to your help I managed to get rid of my sql connections and now read and write directly to and from xml files. However, when I do an xmlwrite, the rows keep getting added to the file rather than replaced. I'm tempted to just erase the file and rewrite it each time. But a better solution might be to create a primary key.
Could someone help me with how to tell an xml dataset that a column is the primary key? Do I need to use an xml schema for this?
Thanks!
|
|
|
|
|
I have problem with the code below.
Add(String, System.Drawing.Image, System.EventHandler)
I don't know how to replace System.EventHandeler
Thanks
................
|
|
|
|
|
Are you trying to modify the add button on the toolstrip?
Nathan Lindley
.NET Aficionado
|
|
|
|
|
Here is an example:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.ToolStrip1.Items.Add("test", Nothing, AddressOf ButtonClickedEventHandler)
End Sub
Public Shared Sub ButtonClickedEventHandler(ByVal sender As Object, ByVal e As System.EventArgs)
MessageBox.Show("This is a test.")
End Sub
Mike Lasseter
|
|
|
|
|
What the problem if I want to get text from the name that i added to display in message box
Thanks
-- modified at 22:30 Saturday 7th October, 2006
................
|
|
|
|
|
I would like to know if there is a way to populate the combo box in VB 6 using data from a certain table's field. for example i have a form that holds employee details but i also want to pick department code from another table how do i go about it?
|
|
|
|
|
The easiest way is to make sure that you join both tables in your SQL statement, so you can loop through the records returned and fill it right away.
Otherwise, you have to loop through the parent records, and find the value of the department code (by looping) in the other records.
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|