|
Populating one my WinForms submenu requires database access over internet.
So it is better to populate it at runtime when in may become visible.
For this I use designer generated code in form constructor:
this.openToolStripMenuItem.DropDownOpening += new <br />
System.EventHandler(this.openToolStripMenuItem_DropDownOpening);
Initially menu does not contain any items.
When I move mouse to aparent menu item all is OK: DropDownOpening event
handler fills this menu with items.
However when I use keyboard keys to move to parent item, this event does not
fire: selection triange does not appear and it is not possible to open
submenu. I tried to use
this.openToolStripMenuItem.CanSelect = true; but got compile error CanSelect being is read only.
How to populate submenu when parent menu item is activated using keyboard ?
Andrus.
Andrus
|
|
|
|
|
Hi Andrus,
I've just taken a look at some code of mine that populates a submenu with a list of available COM ports and I think you have the drop down opening handler attached to the wrong menu item.
You want the selection triangle to appear when you activate the parent of the openToolStripMenuItem which is probably fileToolStripMenuItem. If you build your submenu when the fileToolStripMenuItem drops down it should all start working properly.
Alan.
|
|
|
|
|
Thank you.
I have 3-level menu structure
File
Open company
Company1
Company2
....
Companyn
I want that:
1. Selection triangle for "Open Company" is shown always.
2. Dynamic list Company1 .. Companyn is built only when I move focus to "Open company" item.
Issues:
1. I do'nt know how to enable selection triange initially in "Open company" menu when its list is empty.
2. When I highlight "Open company" menu item using keybord arrows, dynamic list is not populated.
Your suggestion to populate in file menu works but in this case menu is populated always when File menu is opened.
I need that menu is populated only when
In this case owever the dropdown is populated only When "Open Company" is selected from keyboard (selection from mouse works).
Andrus.
Andrus
|
|
|
|
|
Andrus,
I’ve been experimenting with my code to see if I could get the action you desire.
Clearly if you want to see a selection triangle then a submenu must be present. Why not replace a dummy submenu item at run time with your desired menu. Example code from my own application as follows.
private void openToolStripMenuItem_DropDownOpening(object sender, EventArgs e) {
dummyItem = openToolStripMenuItem.DropDownItems[0];
openToolStripMenuItem.DropDownItems.Clear();
ToolStripMenuItem comPortMenuItem;
String[] ports;
app.GetPortNames(out ports);
foreach (String port in ports) {
comPortMenuItem = new ToolStripMenuItem();
comPortMenuItem.Click += new EventHandler(comPortMenuItem_Click);
comPortMenuItem.DisplayStyle = ToolStripItemDisplayStyle.Text;
comPortMenuItem.Size = new System.Drawing.Size(152, 22);
comPortMenuItem.Text = port;
openToolStripMenuItem.DropDownItems.Add(comPortMenuItem);
}
}
private void openToolStripMenuItem_DropDownClosed(object sender, EventArgs e) {
openToolStripMenuItem.DropDownItems.Clear();
openToolStripMenuItem.DropDownItems.Add(dummyItem);
}
It's not very neat but it does work for both mouse and keyboard.
Alan.
|
|
|
|
|
I am creating a form where a user will fill out the form submit and will be sent as an e-mail. By using the asp:FileUpload will be able to send an attachment. I am using the MailMessage class to construct the e-mail and have it sent to a designated e-mail address. Where I am having troubles getting my head around is how to manage the attachments. The site itself is hosted off-site and I do not have a lot of space so the attachment needs to come directly to the building, or be held in a temp folder and be deleted after sending. I tried the following.
if (this.fiupDesign.HasFile)
{
filePath = Server.MapPath("~/App_Support/TempStorage");
filePath = Path.Combine(filePath, Path.GetFileName(this.fiupDesign.FileName));
this.fiupDesign.SaveAs(filePath);
fiupDesign.PostedFile.InputStream.Close();
} //end if
//Construct E-mail
mm = new MailMessage (this.txtEmail.Text, "email@email.com");
mm.IsBodyHtml = false;
mm.Subject = string.Format("Design - {0}", this.txtPatternName.Text);
mm.Body = sbTemplate.ToString();
mm.Attachments.Add(new Attachment(filePath));
sc = new SmtpClient("localhost");
sc.UseDefaultCredentials = true;
sc.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
sc.Send(mm);
/* Clean up temp file */
if (File.Exists(filePath))
File.Delete(filePath);
The problem here is that my cleanup of the temp file tries to delete the attachments to quickly and before they are sent so it throws an error saying "file is in use by another process." How would you of gone about doing this? Any help here would be fantastic. Even if it is an entirely different direction because this above isn't working.
Thank you for your help!
|
|
|
|
|
Wow. Don't write the file to disk just to turn around and read it and then delete it. Jeez dude.
Try using the Documentation for all the classes you are using and you will see that you can use the incoming stream to create the attachment without writing the file to disk.
led mike
|
|
|
|
|
yes you are correct that I am not doing this right. Can anyone expound on the incoming stream and how to use this properly?
Thank you for your help!
|
|
|
|
|
kknepple wrote: Can anyone expound on the incoming stream and how to use this properly?
led mike wrote: Try using the Documentation
Stop making me repeat myself
led mike
|
|
|
|
|
I am sorry to have inconvenienced you but I was looking for help and have been reading the documentation and don't understand it ok? I will continue to read the documentation and I hope I find the answer. I believe these forums are here to help someone who has a question. I do understnad that there is a tendency for some laziness and people are looking to just have other people to do the work for them but I am having trouble understanding this. so if this is not the forum to get help please let me know. I mean do you go to every post and say read the documentation?
yes, you are a better programmer then me.
yes, you have been doing this longer than me.
yes, I do not know where to look.
yes, I came here for help.
is there a programmer out there that would shed some light on the subject? Like what do you need to include to read the data into the MemoryStream and what you need to read the data back out even you led Mike was a beginner at some point and came here for help before you became an MVP.
Thank you for your help!
|
|
|
|
|
kknepple wrote: and have been reading the documentation and don't understand it ok?
yep that's fine. Post the part(s) you don't understand ( and the URL to the source ) and ask specific questions. Folks here will gladly help if you do that.
kknepple wrote: Like what do you need to include to read the data into the MemoryStream
You don't have to, it's already in a stream in memory as part of the FileUpload object. Read the documentation.
led mike
|
|
|
|
|
led mike wrote: Read the documentation.
Wow. Groundhog post.
"Rise and shine campers. It's cold out there."
|
|
|
|
|
I would re-arrange this code a bit.
mm = new MailMessage (this.txtEmail.Text, "email@email.com");
mm.IsBodyHtml = false;
mm.Subject = string.Format("Design - {0}", this.txtPatternName.Text);
mm.Body = sbTemplate.ToString();
if (this.fiupDesign.HasFile)
{
string fileName = Path.GetFileName(this.fiupDesign.FileName);
mm.Attachments.Add(new Attachment(this.fiupDesign.FileContent,fileName));
}
The FileContent property returns a stream (the uploaded file) and the Attachment class has a constructor which takes a stream and the filename to use. This negates ever having to save the file to disk and running into the locking issue.
|
|
|
|
|
Hi guys
I need to write an application in C # that it will auto run when window start up. Need some info and resource on how about creating in? Any example code and sample will be deeply appreciated
Thanks A million
KaKaShi HaTaKe
|
|
|
|
|
You can run pretty much any application at Windows startup by putting a shortcut to the application's executable file in Start Menu - Programs - Startup. You have to check for localization issues (in my Spanish Windows, it's Inicio instead of Startup.)
Environment.GetFolderPath[^] with SpecialFolder.Startup[^] can get you the path to the Startup program group.
I hope this helps!
|
|
|
|
|
also in my application i also need to create an option for user to choose whether they want the option to run on start up... is that any sample code or material i can read about?
KaKaShi HaTaKe
|
|
|
|
|
Depending on your user's choice you should create or delete the shortcut in the location you get with GetFolderPath . I don't have sample code but a Google search on "creating shortcuts C#" should return what you want (as a matter of fact, the first result is a CP article that does exactly what you want.)
|
|
|
|
|
|
Hello,
I am using ReportViewer to generate report. I want my Header to be dislayed in a SubReport.
I am always getting error "SubReport could not be shown".
I am having a class ReportHeader.cs with some properties(UserName, UserDetail etc.). I want this class contents to be displayed in SubReport.
Please tell me step by step, what all i need to do ?
I have gone through so many helps available on net but i am not able to get rid of the error message.
Thanks
Gajesh
|
|
|
|
|
|
setting Format to Custom has worked for me in the past. In fact, I just checked on VS 2k5. If you feel you must then you can set CustomFormat to MM/d/yyyy h:m . Either way, it shouldn't throw any exceptions.
If you're doing this, check the events for the instance of the control to ascertain just where your problem is occurring.
-JC
|
|
|
|
|
THANKS
Have Fun
Never forget it
|
|
|
|
|
Hey all,
The query goes like this...
While browsing the internet on the web browser component,any pop-ups are by default opened on the IE.Is there any way to supress this kind of event and let my own browser open the pop-up?
Thanks in advance....
|
|
|
|
|
Aditya Baraya wrote: Is there any way to supress this kind of event and let my own browser open the pop-up?
It's not your own browser. If it was your code would be parsing the HTML and script and executing the script so yes you could do it. Since it's not "your own browser" then the answer is in the documentation for the browser you are using.
led mike
|
|
|
|
|
There must be some way to do this....
Are you really sure theres no other way to accomplish such a task????
|
|
|
|
|
WOW. Ok that was to a reply from the guy below and he deleted it so it wound up going to you, maybe, if you got it. Anyway.
Aditya Baraya wrote: Are you really sure theres no other way to accomplish such a task????
Not sure what you mean. If there is a way you will have to find it by reading the documentation for the browser control and all it's interfaces, that's all I said in my post.
led mike
|
|
|
|