|
Part of the solution is to define the menu item objects WithEvents thus:
Dim WithEvents MenuItem1 As New System.Windows.Forms.MenuItem
Dim WithEvents MenuItem2 As New System.Windows.Forms.MenuItem
Dim WithEvents MenuItem3 ... etc.
You'll then be able to trap the MenuItemx_Click() events.
A couple of drawbacks though: you cannot define local objects WithEvents, nor can WithEvents be associated with arrays so you'll need to define a bunch of menu item objects with global scope within your class to cater for the maximum number of expected menu items in your config file.
I have had no reason to do dynamic context menus so I'd also be interested in other people's solutions.
...Steve
-- modified at 19:38 Tuesday 13th September, 2005
|
|
|
|
|
By looking at the code it looks like that you defined menuitem* inside the sub Form_load and therefore they are "local" objects. The compiler correctly don't know them (they exist only inside the form_load).
Try to declare them as "global" to the class (adding the withevents clause as stated in the other reply) and then it should be ok.
|
|
|
|
|
I just purchased SQL Server 2000 Developer Edition yesterday from Amazon, and i'm disapointed. when i finally got it up an running, i went to the server explorer in my VB.NET Standard, and when i tried to connect to a database, it said:
"Unable to connect to database.
It is only possible to connect to SQL Server Desktop Engine databases and Microsoft Access databases with this version of Visual Studio."
wtf is up with that? do i need Visual Studio Professional? Enterprise? or do i really have to spend the $2500 on Enterprise Architect? i thought the $50 price tag on SQL Server 2000 Developer Edition meant it was intended for low-budget developers, and considering the $109 price tag on VB.NET Standard, i thought they would go hand-in hand. apparently not.
i can connect to the database programmatically just fine, but the inability to do it visualy is very dissapointing
any help is appreciated.
stephen
|
|
|
|
|
medicenpringles wrote:
but the inability to do it visualy is very dissapointing
You're not missing much. I prefer to do my database work in the Enterprise Manager of SQL Server anyway. Hand coding the database code is a much cleaner approach. All your code is contained to exactly where you put it instead of where the Designer wants to put it.
The Standard Edition of Visual Studio won't connect the Server Explorer to SQL Server. It's limited to the desktop databases only. Visual Studio Professional and above will work though.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
well to be honest, the only real reason i got Developer Edition was for the enterprise manager. if i only used the free Desktop Engine, would Enterprise Manager sill work with maintaining the databases on the Desktop Engine?
|
|
|
|
|
Frankly, I've never tried it. I think it would work, but it might take a couple of hacks to get it there.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I have been working purely as a web developer for some time. My boss now wants me to create my next project as a windows application (VB.NET), which I have never done! My question is what sort of things should I be aware of? I will be using databases, are these treated differently?
Thanks
|
|
|
|
|
Anonymous wrote:
I will be using databases, are these treated differently?
Nope. Data is data. If your application is written correctly into tiers, then you could quite easily use the same business rules and data access classes between an ASP.NET version and a Windows Forms version of your app. There's not too much different from ASP.NET. It's still an event driven model.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have a picturebox that has been populated with an image. I need to determine the path/filename of the image being displayed in the picurebox. Does anyone know of the property that contains the path and filename of an image displayed in a picturebox?
Thanks
Keith
|
|
|
|
|
There is no way to determine this. Not all Images or Bitmaps are created from files, so it's of little use.
Since you loaded the picture box from a file, you've already got the filename. It's just not attached to the Image object. I think your problem will be solved if you exposed your data, like the currently loaded filename, in the correct manner.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Please help me, I've lost my mummy.
I am a class , which inherits a tabpage.
I have a procedure in my tabpage class which needs to update other controls outside of my tabcontrol inwhich i sit.
For example, my tabpage class is within a tabcontrol which is in a form that also has a statusbar.
How can I find it?
I tried doing:
<br />
me.parentform.statusbar1.text = "Loading"
But that doesnt quite work out.
I tried doing:
<br />
dim fmain as Mainform<br />
fmain = ctype(me.parentform,MainForm)<br />
<br />
fmain.statusbar1.text = "Loading"
but that never worked out either.
Is there another way?
|
|
|
|
|
A TabPage doesn't have a ParentForm property, unless your class provides it. It has a Parent property, which points to the container holding the TabPage . This should be the TabControl , not a Form .
The TabPage should not care, or more precisely know, about any object that contains it. Really, what your TabPage should be doing is exposing an event that gives status text information. Then the Form can subscribe to that event and get notifications from your TabPage. This also makes it much easier to redirect status messages to other destinations, such as the event log or to a file.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
ahaa,
I like your way of thinking Dave, I'm going to have to try that.
However....
Your method destroys my application design because of this...
In my tabpage, I also have a text box, which the user inputs a value into.
This text box, once value has changed, then needs to update a textbox in another tabpage.
Tabpage 1 is not aware of any existence of tabpage 2.
Therefore how can I raise an event in tabpage 1, because tabpage 2 will never know?
Your thoughts appreciated.
Andy
|
|
|
|
|
You're following the shortcut of "visual elements must update other visual elements with new data". WRONG! Visual elements are responsible for updating their small part of a data store. Their sole function is life is to manage the input of data and store it somewhere. If that element is supposed to display data too, it should get it from that same data store, or class (hint, hint).
In your example, a TextBox on TabPage1 has to update information in a TextBox on TabPage2. If each TabPage, or visual element should not know anything of visual elements outside their own Form, or TabPage, how is this data supposed to get back to the TextBox of TabPage2? Easy, create a storage class that holds all the information that these TabPages manage. When TabPage1 needs to make changes to TabPage2, it's the data that changes in the storage class. When TabPage2 is displayed, it's responsible for retrieving the current information from the storage class and populating its controls with the updated information.
Each TabPage should know about it's little section of the storage class, nothing else.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thankyou for replying Dave. This is turning into a very interesting discussion. You are correct in your initial statement. I can see its a very bad way of programming, but also a very simple way of getting a job done quickly.
Your right, creating a class to encapsulate the data would be perfect. But this is triggered by an event within tabpage2, ie: its own activation. Primarily because its hidden until the user clicks on its tab.
What if the trigger occurred somewhere else?
Lets imagine for a moment that they are not tabpages, but infact child windows, side by side, within an mdi form.
The user fills in a value into a textbox in childwindow1. But childwindow2 is still visible on the screen, next to childwindow1.
There's no event triggered within childwindow2, so therefore its textbox will not refresh with the new data.
If each childwindow knew who its parent was, childwindow1 could raise an event and cause a cascading situation until childwindow2 got updated. But that could get very messy.
Maybe a timer in childwindow2 to check the class for any changes? Again, horrible and messy.
This still returns to my original question. If a child is not aware of any other siblings and their events, its only link is the parent?
Look forward to your reply.
Andy
|
|
|
|
|
Just add some events to that datastore class. Perhaps have it (the datastore class) raise events that each of your tabs can monitor. They must, afterall, be aware of the class that is holding the data. Why not make them aware of events in that class that tell anything that sets or retrieves data from it what is going on.
That should work with your mdi form example also if I'm not mistaken.
Beaniiman
|
|
|
|
|
andymknight wrote:
but also a very simple way of getting a job done quickly.
If it's not done right, it's not done. It's just hacked togther and "works".
andymknight wrote:
Your right, creating a class to encapsulate the data would be perfect. But this is triggered by an event within tabpage2, ie: its own activation. Primarily because its hidden until the user clicks on its tab.
Yep. Remember, the user interface was not meant to store the data, just display it and process input.
andymknight wrote:
What if the trigger occurred somewhere else?
Lets imagine for a moment that they are not tabpages, but infact child windows, side by side, within an mdi form.
The user fills in a value into a textbox in childwindow1. But childwindow2 is still visible on the screen, next to childwindow1.
That's a hacked example. An MDI interface was meant to have Multiple Documents using the same editor. Not have multiple pages open all modifying the same data. If you've got this situation, you really have to rethink your data model.
andymknight wrote:
The user fills in a value into a textbox in childwindow1. But childwindow2 is still visible on the screen, next to childwindow1.
There's no event triggered within childwindow2, so therefore its textbox will not refresh with the new data.
There will be if, like Beaniiman said, the data class raises events that say "such-and-such" changed! Ever look at the events of various controls? Same exact thing. If you change a property in a control, an event fires off, usually by the name PropertyChanged .
andymknight wrote:
If each childwindow knew who its parent was, childwindow1 could raise an event and cause a cascading situation until childwindow2 got updated. But that could get very messy.
Maybe a timer in childwindow2 to check the class for any changes? Again, horrible and messy.
Messy? That's why no-one worth their weight does this!
andymknight wrote:
This still returns to my original question. If a child is not aware of any other siblings and their events, its only link is the parent?
Beaniiman beat me to it, but your data class can expose its fields as Properties. Then when TabPage1, or ChildForm1, changes anything in the dataclass, the Property code fires a PropertyChanged event. Any subscribers to the event, like TabPage2 or ChildForm2, get notified of the change and can update themselves with the new value. Notice, this still follows the model of various visual elements maintaining their own little part of the dataset.
There is nothing that says a data class can't fire it's own events when a field in the data class changes.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well, what can I say? Thankyou Dave, and Beaniiman.
In such a small thread, I've learnt alot about design techniques and how I should code differently.
Thankyou for your input, its been extremely interesting.
Andy
|
|
|
|
|
I have an sql query like "select id, text, time from table" filling a datagrid.
i have a problem with the datagrid values in the time cell. It says that has null values or 00:00:00 value.
I don't know why. If I make the same query directly in mysql, it returns correct values.
I test the same query with a little variation "select id, text, HOUR(time) from table".This time, the datagrid shows the correct values (12, 06, etc).
Someone knows why is happening this?
|
|
|
|
|
Well, I solved the problem this workaround:
"select id, text, DATE_FORMAT(time,'%H:%i:%S') from table"
Hope this helps to somebody!
|
|
|
|
|
I created this user control that has various linkbuttons to other parts of my web application. I want to disable some of the linkbuttons so that users can't access other pages. I have tried various different ways but as of yet no joy. I have made the linkbuttons in the usercontrol.ascx public so all i really need to kno is how to disable them from the .aspx page.
Any advice is greatly appreciated.
|
|
|
|
|
hi there,
what problem u got when trying to disable linkbutton?
it's ok with me but just for asp button, not try with linkbutton yet.
<< >>
|
|
|
|
|
Basically whenever i put the line in
usercontrol.linkbutton1.enable = False
it won't set the enabled property to false.
gfhg
|
|
|
|
|
how about if u put the link button in web page not in usercontrol?
it would be better to find out the cause if u can post the snippet of code.
<< >>
|
|
|
|
|
ok below is the code for the USER CONTROL
Imports System.Data.SqlClient
Public Class Topmenu
Inherits System.Web.UI.UserControl
Public WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButton
Public WithEvents LinkButton2 As system.Web.UI.WebControls.Linkbutton
Public WithEvents tbltopmenu As System.Web.UI.HTMLControls.HTMLTable
Dim conn As SQLConnection......
Public Sub Page_Load(....)
End Sub
Private Sub LinkButton1_Click(....)
Response.Redirect("menu.aspx")
End Sub
Private Sub LinkButton2_click(....)
Response.Redirect("logout.aspx")
End Sub
End Class
And this is the code I have in the Page_load event on a number of .aspx pages
Public Sub Page_Load(......)
topmenu.Linkbutton1.Enabled = False
End Sub
gfhg
|
|
|
|
|