|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
is it save to call functions from another form?Hi All,
I want to call a function from another page. I've made it Public but still it doesn't recognize it. called from form frmZoeken: Explorer1.AddFolder2Database(nodeID, sNewFolder) Explorer1.TreeView.Refresh() Marco Co wrote:
> Hi All, A web page or a windows Form?> > I want to call a function from another page. > I've made it Public but still it doesn't recognize it. The compiler says "...isn't a member of..."?Or doesn't it find variable 'Explorer1'? > What's the declaration of Explorer1? Where is it declared? Does the type of > called from form frmZoeken: > Explorer1.AddFolder2Database(nodeID, sNewFolder) > Explorer1.TreeView.Refresh() the variable have the members AddFolder2Database and TreeView? Are they accessible (Public/Friend if in the same assembly)? Armin
Show quote
Hide quote
On 24 mei, 13:21, "Armin Zingler" <az.nos***@freenet.de> wrote: Armin,> Co wrote: > > Hi All, > > > I want to call a function from another page. > > A web page or a windows Form? > > > I've made it Public but still it doesn't recognize it. > > The compiler says "...isn't a member of..."? > Or doesn't it find variable 'Explorer1'? > > > > > called from form frmZoeken: > > Explorer1.AddFolder2Database(nodeID, sNewFolder) > > Explorer1.TreeView.Refresh() > > What's the declaration of Explorer1? Where is it declared? Does the type of > the variable have the members AddFolder2Database and TreeView? Are they > accessible (Public/Friend if in the same assembly)? > > Armin I have been looking at this page but I can't make any sense of it: http://bytes.com/groups/net-vb/388067-refreshing-main-form-another-form What I want to do is the following. I have a mainform called Explorer1 which has a Treeview on it. Now from the menu I open the search page called: frmZoeken. On frmZoeken I click a button which creates a new node in the Treeview of Explorer1 called "New Folder" So I want the node added and refresh the Treeview so the node is shown: Explorer1.AddFolder2Database(nodeID, sNewFolder) Explorer1.TreeView.Refresh() With my code the node is added but it doesn't show. Marco Co wrote:
Show quoteHide quote > On 24 mei, 13:21, "Armin Zingler" <az.nos***@freenet.de> wrote: You really must be more precize if you expect help from others. Above you>> Co wrote: >>> Hi All, >> >>> I want to call a function from another page. >> >> A web page or a windows Form? >> >>> I've made it Public but still it doesn't recognize it. >> >> The compiler says "...isn't a member of..."? >> Or doesn't it find variable 'Explorer1'? >> >> >> >>> called from form frmZoeken: >>> Explorer1.AddFolder2Database(nodeID, sNewFolder) >>> Explorer1.TreeView.Refresh() >> >> What's the declaration of Explorer1? Where is it declared? Does the >> type of the variable have the members AddFolder2Database and >> TreeView? Are they accessible (Public/Friend if in the same >> assembly)? >> >> Armin > > Armin, > > I have been looking at this page but I can't make any sense of it: > > http://bytes.com/groups/net-vb/388067-refreshing-main-form-another-form > > What I want to do is the following. > I have a mainform called Explorer1 which has a Treeview on it. > Now from the menu I open the search page called: frmZoeken. > On frmZoeken I click a button which creates a new node in the Treeview > of Explorer1 called "New Folder" > > So I want the node added and refresh the Treeview so the node is > shown: > Explorer1.AddFolder2Database(nodeID, sNewFolder) > Explorer1.TreeView.Refresh() > > With my code the node is added but it doesn't show. wrote "it doesn't recognize it". Now you write "it doesn't show". I'm gonna assume the latter. Or, "it doesn't show" via intellisense? I don't know. Seems to be one of the problems MSFT reintroduced with the reintroduction of the fatal Form "default instances" they got rid of in VB 2002/2003. Was meant to make it easier for beginners. Yeah, sure - but it doesn't. I can't tell you how much I "dislike" these default instances. I hardly know where to start..., well, the first thing you have to know is that VB does several things under the hood. This makes it sometimes complicated to understand how things work. One invisible class it compiles into your project is called 'MyProject' under the 'My' namespace. For example, the full name is "WinApplication1.My.MyProject". It's a special class that we call a Module in VB syntax. In addition, another invisible class is created. It's called 'MyForms'. It is as a nested class inside class MyProject. It has one property per Form in the project. Each property's name is the same name as the Form's class name. Each property returns an instance of a Form of the corresponding Form type. The module MyProject has a property called Forms. It is of type MyForms. Whenever you write: FormClassName.Member the VB compiler behaves very special: 'FormClassName' is resolved to Forms.FormClassName. As 'MyProject' is a Module, the Forms property is actually a shared member. Consequently, there can be exactly one default instance of each Form in your project. So far, so bad. Back to your project. If you write 'Explorer1.AddFolder2Database', you are accessing the default instance of the Form. Hovering the mouse above 'Explorer1', the IDE is incorrectly showing "Class Explorer1". Well, it's also a class, but not in this context. If it was resolved to the class name, you would only be able to access the shared members. In fact you are able to write Explorer1.Show How can this be possible as Explorer1 is a class but Show is an _instance_ member? Actually Explorer1 is a property, but MSFT doesn't want us to know this and prefers to hide the details. (Hopefully) coming to the solution: How did you create an instance of Form Explorer1 that you see on the screen? If you add folders (in AddFolder2Database) and they don't appear on your visible Form, I guess you didn't show the default instance but are you adding the items to the default instance. BTW, why do you call TreeView.Refresh? (I do have a reason for this question but will wait for your answer.) If you don't want to be confused by this intransparent and badly designed model (namely the whole My.Crap), just add _mytype="empty" to the compile constants in your project's properties. I've created a project template for this. But, don't be surprised if you will have additional 1001 questions after that. ;-) (No, it would not solve your problem! - but mine) See also: http://msdn.microsoft.com/en-us/library/ms233781.aspx (anyway, it does not really make things more comprehensive) Armin
Show quote
Hide quote
On 24 mei, 17:11, "Armin Zingler" <az.nos***@freenet.de> wrote: Armin,> Co wrote: > > On 24 mei, 13:21, "Armin Zingler" <az.nos***@freenet.de> wrote: > >> Co wrote: > >>> Hi All, > > >>> I want to call a function from another page. > > >> A web page or a windows Form? > > >>> I've made it Public but still it doesn't recognize it. > > >> The compiler says "...isn't a member of..."? > >> Or doesn't it find variable 'Explorer1'? > > >>> called from form frmZoeken: > >>> Explorer1.AddFolder2Database(nodeID, sNewFolder) > >>> Explorer1.TreeView.Refresh() > > >> What's the declaration of Explorer1? Where is it declared? Does the > >> type of the variable have the members AddFolder2Database and > >> TreeView? Are they accessible (Public/Friend if in the same > >> assembly)? > > >> Armin > > > Armin, > > > I have been looking at this page but I can't make any sense of it: > > >http://bytes.com/groups/net-vb/388067-refreshing-main-form-another-form > > > What I want to do is the following. > > I have a mainform called Explorer1 which has a Treeview on it. > > Now from the menu I open the search page called: frmZoeken. > > On frmZoeken I click a button which creates a new node in the Treeview > > of Explorer1 called "New Folder" > > > So I want the node added and refresh the Treeview so the node is > > shown: > > Explorer1.AddFolder2Database(nodeID, sNewFolder) > > Explorer1.TreeView.Refresh() > > > With my code the node is added but it doesn't show. > > You really must be more precize if you expect help from others. Above you > wrote "it doesn't recognize it". Now you write "it doesn't show". I'm gonna > assume the latter. Or, "it doesn't show" via intellisense? I don't know. > > Seems to be one of the problems MSFT reintroduced with the reintroduction of > the fatal Form "default instances" they got rid of in VB 2002/2003. Was > meant to make it easier for beginners. Yeah, sure - but it doesn't. I can't > tell you how much I "dislike" these default instances. > > I hardly know where to start..., well, the first thing you have to know is > that VB does several things under the hood. This makes it sometimes > complicated to understand how things work. One invisible class it compiles > into your project is called 'MyProject' under the 'My' namespace. For > example, the full name is "WinApplication1.My.MyProject". It's a special > class that we call a Module in VB syntax. In addition, another invisible > class is created. It's called 'MyForms'. It is as a nested class inside > class MyProject. It has one property per Form in the project. Each > property's name is the same name as the Form's class name. Each property > returns an instance of a Form of the corresponding Form type. The module > MyProject has a property called Forms. It is of type MyForms. > > Whenever you write: > > FormClassName.Member > > the VB compiler behaves very special: 'FormClassName' is resolved to > Forms.FormClassName. As 'MyProject' is a Module, the Forms property is > actually a shared member. Consequently, there can be exactly one default > instance of each Form in your project. > > So far, so bad. Back to your project. If you write > 'Explorer1.AddFolder2Database', you are accessing the default instance of > the Form. Hovering the mouse above 'Explorer1', the IDE is incorrectly > showing "Class Explorer1". Well, it's also a class, but not in this context. > If it was resolved to the class name, you would only be able to access the > shared members. In fact you are able to write > > Explorer1.Show > > How can this be possible as Explorer1 is a class but Show is an _instance_ > member? Actually Explorer1 is a property, but MSFT doesn't want us to know > this and prefers to hide the details. > > (Hopefully) coming to the solution: How did you create an instance of Form > Explorer1 that you see on the screen? If you add folders (in > AddFolder2Database) and they don't appear on your visible Form, I guess you > didn't show the default instance but are you adding the items to the default > instance. > > BTW, why do you call TreeView.Refresh? (I do have a reason for this question > but will wait for your answer.) > > If you don't want to be confused by this intransparent and badly designed > model (namely the whole My.Crap), just add > > _mytype="empty" > > to the compile constants in your project's properties. I've created a > project template for this. But, don't be surprised if you will have > additional 1001 questions after that. ;-) (No, it would not solve your > problem! - but mine) > > See also:http://msdn.microsoft.com/en-us/library/ms233781.aspx > (anyway, it does not really make things more comprehensive) > > Armin I must admit that I find it a very complicated story. Which BTW has all to do with me and not with you. I think I will have to skip this part because my knowledge is not enough. On your Q of why I refresh the Treeview is because a node was added. I thought you always had to do a refresh afterwards. Marco Co wrote:
> This time long story short: How did you show Explorer1? Is it the startup> I must admit that I find it a very complicated story. > Which BTW has all to do with me and not with you. > I think I will have to skip this part because my knowledge is not > enough. form? Did you write Explorer1.Show? Or did you write dim f as new explorer1 f.show anywhere? > On your Q of why I refresh the Treeview is because a node was added. The Treeview updates itself if you change something. Doesn't it work without > I thought you always had to do a refresh afterwards. Refresh? Armin Armin Zingler wrote:
Show quoteHide quote > Co wrote: I'm just winging it now, but it cross my mind when you said this that >> >> I must admit that I find it a very complicated story. >> Which BTW has all to do with me and not with you. >> I think I will have to skip this part because my knowledge is not >> enough. > > This time long story short: How did you show Explorer1? Is it the startup > form? Did you write Explorer1.Show? Or did you write > > dim f as new explorer1 > f.show > > anywhere? > >> On your Q of why I refresh the Treeview is because a node was added. >> I thought you always had to do a refresh afterwards. > > The Treeview updates itself if you change something. Doesn't it work > without Refresh? this is one of the GUI OOPS optimization concept that Anders did in Delphi GUI OOPs brought to .NET GUI OOPs - events are not triggered if the "value" has not changed. In other words, repeating this TextBox1.Text = "foobar" TextBox1.Text = "foobar" TextBox1.Text = "foobar" TextBox1.Text = "foobar" TextBox1.Text = "foobar" should only trigger one event because the value did not change. This idea is a major advancement in Message Queue optimization to minimize automatic event propagation in GUI oops design. For example, with three controls in a form: TextBox1 with text = "" ListBox1 to show change events Button1 to start test Public nChanged As Integer = 0 Private Sub TextBox1_TextChanged( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles TextBox2.TextChanged nChanged += 1 ListBox1.Items.Add("Changed: " + Str(nChanged)) End Sub Private Sub Button1_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = "Foobar" TextBox1.Text = "Foobar" TextBox1.Text = "Foobar" TextBox1.Text = "Foobar" TextBox1.Text = "Foobar" End Sub When you vlick Button1, you will see only 1 event logged. Change it to: TextBox1.Text = "Foobar" TextBox1.Text = "Foobar" TextBox1.Text = "Foobar1" TextBox1.Text = "Foobar" TextBox1.Text = "Foobar2" and you should see 4 change events logged. Again, I am just winging it, maybe that is what he is seeing? -
Show quote
Hide quote
On 24 mei, 22:04, "Armin Zingler" <az.nos***@freenet.de> wrote: It doesn't work with refreshing and it doesn't work without.> Co wrote: > > > I must admit that I find it a very complicated story. > > Which BTW has all to do with me and not with you. > > I think I will have to skip this part because my knowledge is not > > enough. > > This time long story short: How did you show Explorer1? Is it the startup > form? Did you write Explorer1.Show? Or did you write > > dim f as new explorer1 > f.show > > anywhere? > > > On your Q of why I refresh the Treeview is because a node was added. > > I thought you always had to do a refresh afterwards. > > The Treeview updates itself if you change something. Doesn't it work without > Refresh? > > Armin The new node isn't shown. Explorer1 is my main form but it is called from within my login form: Explorer1.Show() then the login form is hidden. from within Explorer1 load event: frmLogin.Hide() Marco Co wrote:
Show quoteHide quote > On 24 mei, 22:04, "Armin Zingler" <az.nos***@freenet.de> wrote: You're right, if it's added to an invisible Form, refreshing doesn't help. >> Co wrote: >> >>> I must admit that I find it a very complicated story. >>> Which BTW has all to do with me and not with you. >>> I think I will have to skip this part because my knowledge is not >>> enough. >> >> This time long story short: How did you show Explorer1? Is it the >> startup form? Did you write Explorer1.Show? Or did you write >> >> dim f as new explorer1 >> f.show >> >> anywhere? >> >>> On your Q of why I refresh the Treeview is because a node was added. >>> I thought you always had to do a refresh afterwards. >> >> The Treeview updates itself if you change something. Doesn't it work >> without Refresh? >> >> Armin > > It doesn't work with refreshing and it doesn't work without. > The new node isn't shown. :-) In this case I've run out of ideas. From here it's hard to say. If you don't > Explorer1 is my main form but it is called from within my login form: > > Explorer1.Show() > > then the login form is hidden. > from within Explorer1 load event: > frmLogin.Hide() create another instance of Explorer1, it should work. Another attempt: What does the code to add the node look like? Are you performing any long running actions directly after adding the node? Armin
Show quote
Hide quote
On 25 mei, 00:22, "Armin Zingler" <az.nos***@freenet.de> wrote: Armin,> Co wrote: > > On 24 mei, 22:04, "Armin Zingler" <az.nos***@freenet.de> wrote: > >> Co wrote: > > >>> I must admit that I find it a very complicated story. > >>> Which BTW has all to do with me and not with you. > >>> I think I will have to skip this part because my knowledge is not > >>> enough. > > >> This time long story short: How did you show Explorer1? Is it the > >> startup form? Did you write Explorer1.Show? Or did you write > > >> dim f as new explorer1 > >> f.show > > >> anywhere? > > >>> On your Q of why I refresh the Treeview is because a node was added. > >>> I thought you always had to do a refresh afterwards. > > >> The Treeview updates itself if you change something. Doesn't it work > >> without Refresh? > > >> Armin > > > It doesn't work with refreshing and it doesn't work without. > > The new node isn't shown. > > You're right, if it's added to an invisible Form, refreshing doesn't help.. > :-) > > > Explorer1 is my main form but it is called from within my login form: > > > Explorer1.Show() > > > then the login form is hidden. > > from within Explorer1 load event: > > frmLogin.Hide() > > In this case I've run out of ideas. From here it's hard to say. If you don't > create another instance of Explorer1, it should work. > > Another attempt: What does the code to add the node look like? Are you > performing any long running actions directly after adding the node? > > Armin this is what happens: from frmZoeken I call the save to Treeview option in the menu: Case "Opslaan" SaveQueryInTreeview() Private Sub SaveQueryInTreeview() Dim sNewFolder As String = "Nieuwe Map" Dim node = Explorer1.TreeView.TopNode Dim nodeID = node.row("ID") node.Nodes.Add(sNewFolder) Explorer1.AddFolder2Database(nodeID, sNewFolder) 'Explorer1.TreeView.Refresh() End Sub From the main form Explorer1 the node is added. Then the folder number is added to the database: Public Sub AddFolder2Database(ByVal iParent As Integer, ByVal sFolderName As String) 'this code will add a new folder to the database conn.Open() Dim sql As String = "SELECT * FROM Kabinet" Dim strTable As String = "Kabinet" Dim da As New OleDb.OleDbDataAdapter(sql, conn) Dim cb As New OleDb.OleDbCommandBuilder(da) Dim ds As New DataSet Dim newRow As DataRow cb.QuotePrefix = "[" cb.QuoteSuffix = "]" Try da.FillSchema(ds, SchemaType.Source, strTable) newRow = ds.Tables(strTable).NewRow() newRow("foldername") = sFolderName newRow("parent-id") = iParent 'add the new row to the dataSet ds.Tables(strTable).Rows.Add(newRow) 'sent the updated dataSet to the database da.Update(ds, strTable) Catch oException As OleDbException MessageBox.Show(oException.Message) Catch oException As Exception MessageBox.Show(oException.Message) End Try conn.Close() 'now let's update the treeview with the new node. TreeView.Nodes.Clear() Call LoadTree() End Sub So everything here is done except that the newly added node isn't shown. Marco
Show quote
Hide quote
On 25 mei, 00:22, "Armin Zingler" <az.nos***@freenet.de> wrote: I think I might have found it:> Co wrote: > > On 24 mei, 22:04, "Armin Zingler" <az.nos***@freenet.de> wrote: > >> Co wrote: > > >>> I must admit that I find it a very complicated story. > >>> Which BTW has all to do with me and not with you. > >>> I think I will have to skip this part because my knowledge is not > >>> enough. > > >> This time long story short: How did you show Explorer1? Is it the > >> startup form? Did you write Explorer1.Show? Or did you write > > >> dim f as new explorer1 > >> f.show > > >> anywhere? > > >>> On your Q of why I refresh the Treeview is because a node was added. > >>> I thought you always had to do a refresh afterwards. > > >> The Treeview updates itself if you change something. Doesn't it work > >> without Refresh? > > >> Armin > > > It doesn't work with refreshing and it doesn't work without. > > The new node isn't shown. > > You're right, if it's added to an invisible Form, refreshing doesn't help.. > :-) > > > Explorer1 is my main form but it is called from within my login form: > > > Explorer1.Show() > > > then the login form is hidden. > > from within Explorer1 load event: > > frmLogin.Hide() > > In this case I've run out of ideas. From here it's hard to say. If you don't > create another instance of Explorer1, it should work. > > Another attempt: What does the code to add the node look like? Are you > performing any long running actions directly after adding the node? > > Armin When I reload the treeview the new nodes aren't add. Public Sub LoadTree() ' TODO: Add code to add items to the treeview Dim sql As String = "SELECT * FROM Kabinet" Dim cmd As New OleDbCommand(sql, conn) Dim dr As OleDbDataReader conn.Open() dr = cmd.ExecuteReader() 'if this is a rebuild then we don't have to add new columns to the datatable If dt.Columns.Count = 0 Then dt.Columns.Add("ID", GetType(Integer)) dt.Columns.Add("Name", GetType(String)) dt.Columns.Add("IDParent", GetType(Integer)) End If If dt.Rows.Count = 0 Then While dr.Read() dt.Rows.Add(dr.Item("Id"), dr.Item("foldername"), dr.Item("parent-Id")) End While End If AddNodes(TreeView.Nodes, dt.Select("ISNULL(IDParent, -1) = -1")) dr.Close() conn.Close() End Sub The next line I think is killing me: 'if this is a rebuild then we don't have to add new columns to the datatable Am I right? Marco Co wrote:
> Am I right? I currently can't follow you (and won't have time til tonight), so if anybody else may give you a hand...? Thx. Armin Co,
Did you see that it was something that did not work and the question was how to make it to work. The reply was simple, don't use it, it .................., could have been my reply. Never use a second form to do Data Access, simply make a Data Class in your project or in a separate data layer (you can better do the first), then you can use that in all your forms, Cor Show quoteHide quote "Co" <vonclausow***@gmail.com> wrote in message news:b135fddc-2532-40f7-ac62-8ed05e5002c5@w40g2000yqd.googlegroups.com... > On 24 mei, 13:21, "Armin Zingler" <az.nos***@freenet.de> wrote: >> Co wrote: >> > Hi All, >> >> > I want to call a function from another page. >> >> A web page or a windows Form? >> >> > I've made it Public but still it doesn't recognize it. >> >> The compiler says "...isn't a member of..."? >> Or doesn't it find variable 'Explorer1'? >> >> >> >> > called from form frmZoeken: >> > Explorer1.AddFolder2Database(nodeID, sNewFolder) >> > Explorer1.TreeView.Refresh() >> >> What's the declaration of Explorer1? Where is it declared? Does the type >> of >> the variable have the members AddFolder2Database and TreeView? Are they >> accessible (Public/Friend if in the same assembly)? >> >> Armin > > Armin, > > I have been looking at this page but I can't make any sense of it: > > http://bytes.com/groups/net-vb/388067-refreshing-main-form-another-form > > What I want to do is the following. > I have a mainform called Explorer1 which has a Treeview on it. > Now from the menu I open the search page called: frmZoeken. > On frmZoeken I click a button which creates a new node in the Treeview > of Explorer1 called "New Folder" > > So I want the node added and refresh the Treeview so the node is > shown: > Explorer1.AddFolder2Database(nodeID, sNewFolder) > Explorer1.TreeView.Refresh() > > With my code the node is added but it doesn't show. > > Marco
use variable as textbox name?
treeview in windowsdialog Call button click event Bracketed types Using function with PChar data type Visual Studio 2008 and Classes Inheriting From System.Web.UI.WebControls.Style Problem with embedded carriage returns trouble reading word documents Good tutorial for working with XML still problems reading word documents... |
|||||||||||||||||||||||