|
DataSource
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
OK. I'm workin on this program and theres this one part of it that loads all of the names of the files in a certain folder, and then adds them to a context menu. Now here is where i run into my problem. I want to make it so that you can click on the menu item in the context menu (which was loaded when the program opened) and have it open its corresponding file in the folder it was loaded from.
Here is the code i used to load the files:
string[] files = Directory.GetFiles(@"docs\");<br />
int fnumber = files.Length;<br />
<br />
for(int cNumber = 0; cNumber != fnumber; cNumber++)<br />
{<br />
string fileName = Path.GetFileNameWithoutExtension(files[cNumber]);<br />
MenuItem menuItem = new MenuItem();<br />
menuItem.Text = fileName;<br />
contextMenu.MenuItems.Add(0, menuItem);<br />
}
Now all i need is an event handler for each menu item that can open the right file. If you know how to do this, then please tell me. Thanks.
By BigBlob202
check out my site - Dinco Inc. - I just started it so theres not much on it.
|
|
|
|
|
You can simply attach an event handler to your MenuItem object.
MenuItem mi = new MenuItem();
mi.Click += new System.EventHandler(this.MenuClick);
...
private void MenuClick(object sender, System.EventArgs e)
{
MenuItem mi = sender as MenuItem;
if(mi != null)
{
}
}
- Nick Parker My Blog
|
|
|
|
|
OK ive put that in the code but now i have no idea how to tell the event handler which menu item was clicked. Thanks so much!!
By BigBlob202
check out my site - Dinco Inc. - I just started it so theres not much on it.
|
|
|
|
|
It appeared in your case you were assigning the Text property of the MenuItem to be a filename. Once you cast the sender as a MenuItem and confirm the cast didn't fail (by checking for null), you can then check the MenuItem (i.e.; mi in my example) for it's Text property. Try throwing a MessageBox.Show(mi.Text); after your check for null to see what I am talking about. This will tell you exactly what was clicked.
- Nick Parker My Blog
|
|
|
|
|
Thank you so much. It worked perfectly!! If you wanna see the program i was making then go to my site - Dinco Inc. - The program is a miniware program called Desktop Saver. It should be up at least by the middle of next week. Thanks Again!
By BigBlob202
|
|
|
|
|
Hello,
My program needs to access a network share and either copy files from the share or else just execute a program. First I have the client check if it can see the share:
if(Directory.Exists("\\\\server\\share") {
// do whatever
}
else {
// couldn't see share
// provided the share is online
// I assume the client does not have proper permission
// basically I want to "net use" here.
}
Is there a function that does this? Or do i need to start a "net use" process? What is the preferred method of gaining access to a remote share through C#?
Thanks,
Ian
|
|
|
|
|
just use it like a normal file resource
|
|
|
|
|
As the first post mentioned - just access the file using a UNC path. If you get an UnauthorizedException , this means you don't have permissions. The correct way is to prompt the user for credentials and impersonate them using those credentials. For an example of impersonation using .NET, see the documentation for the WindowsIdentity.Impersonate method in the .NET Framework SDK.
If you want to go to the trouble of forming a net use statement (using /user and prompting for the password), you could do that but you'll have to make sure you change all UNC references so that they use the new mapped drive letter.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
This might be a stupid question but I can't figure it out:
I am writing a simple c# console app that calls another executable (usually a batch file but sometimes an exe). I want the other executable called to run in the same window that I ran the c# app.
For instance, one of the executables I can call is an exe and it prints the build# to the screen. If I call it from the command prompt manually it runs in the same window:
c:\>\\server\share\getversion
build number: 3000
c:\>
However in my C# app it always opens getversion.exe in a new window. How do I make it run in the current command window? I tried using ProcessStartInfo.CreateNoWindow = false but that doesn't work.
if(Directory.Exists("\\\\server\\share\\"))
{
Process myProcess = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "\\\\server\\share\\getversion.exe";
myProcess.StartInfo = startInfo;
myProcess.Start();
}
When I run ConsoleApplication1.exe from a command prompt, it opens another command window, executes getversion.exe (which then closes immediately and you can't even see what it said).
|
|
|
|
|
Arg I figured it out. I used UseShellExecute = false and took out the CreateNoWindow = true.
|
|
|
|
|
Hi everyone,
I guess that this is just somethink trivial, but I can't seem to find how to do it. I have a single DataGrid in my Windows Form which I am using to display a DataSet containing two tables constrained by a parent-child relationship. I'm using the DataGrid.SetDataBinding method to databind the datagrid to the first (parent) table. The DataGrid automatically displays a small "+" buttons in each rowheader which allows the user to navigate to related records in the child table. The child table contains a header showing information about the parent table (determined by the ParentRowDisplayStyle property of the DataGrid, I think). This is all nice, but is there any way to navigate back to the parent table? Or do I have to add another control to the form (button) which will call some DataGrid's method to achieve this?
Thanks a lot in advance!
rado
Radoslav Bielik
http://www.neomyz.com/poll [^] - Get your own web poll
|
|
|
|
|
Set both AllowNavigation and CaptionVisible to true . The caption will show some navigational buttons.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Oh, thanks a lot, I didn't use the caption at all, I will try it!
Thanks again
rado
Radoslav Bielik
http://www.neomyz.com/poll [^] - Get your own web poll
|
|
|
|
|
I have just tried it and it works, thanks! I've got one (well, two) more questions, though:
1. Regardless of the value of ParentRowLabelStyle property, the ParentRow always displays the table name as well as all columns. What am I doing wrong?
2. When users click the "+" button in the parent table, the name of the relation appears and once they click on it, they are navigated to the chlid table. Is it possible to display something else in place of the relation name (something more user friendly) or not?
Thanks again!
rado
Radoslav Bielik
http://www.neomyz.com/poll [^] - Get your own web poll
|
|
|
|
|
Radoslav Bielik wrote:
1. Regardless of the value of ParentRowLabelStyle property, the ParentRow always displays the table name as well as all columns. What am I doing wrong?
Try setting DataGrid.ParentRowsVisible to false .
Radoslav Bielik wrote:
2. When users click the "+" button in the parent table, the name of the relation appears and once they click on it, they are navigated to the chlid table. Is it possible to display something else in place of the relation name (something more user friendly) or not?
Why don't you give the relationship a better name? That'd be the easiest way. Otherwise, changing this will be either impossible (without messy reflection) or difficult, since those types of things are wrapped up into private methods - perhaps even nested classes - of the DataGrid control. Learn to read Intermediate Language (IL) - the language to which all .NET languages compile - and use ildasm.exe that comes with the .NET Framework SDK to see what's going on inside it if you want to go down this route. The first suggestion would be far easier, though.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
Try setting DataGrid.ParentRowsVisible to false.
I did this but it didn't help - when I click the button to show the parent row, it contains all information even if
DataGrid.ParentRowsLabelStyle=DataGridParentRowsLabelStyle.None<br /> I already thought that I misunderstood the concept or something, but then I tried to find the ParentRowsLabelStyle in the Designer Generated Code, but it wasn't there, and when I manually added the ParentRowsLabelStyle initialization to the form constructor, it started to work as expected, but I don't know why it wasn't there when I was changing it's value in the designer. Strange.
[Update]
I've tried to add the ParentRowsLabelStyle initialization into the designer generated code, and then tried to change the value of this property in the designer, and it disappeared from the source. I will rather keep it in the form constructor.
[/Update]
Heath Stewart wrote:
Why don't you give the relationship a better name? That'd be the easiest way.
I already did, I just wanted to know if there isn't a better and if I'm not doing it the wrong way Thanks!
rado
Radoslav Bielik
http://www.neomyz.com/poll [^] - Get your own web poll
|
|
|
|
|
I have written a trace listener that has at least one worker thread to process an internal buffer. When the Close method is called explicitly from within the hosting application, everthing is fine and dandy, but if i add the TraceListener from the system.diagnostics section of the config file, the Close method doesn't ever get called. Does anyone have any idea when that method gets called when added through the config file?
|
|
|
|
|
The correct solution is probably to implemente the IDisposable interface on your trace listener. When that object is disposed, you can call the Close method yourself.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
Hmm - turns out a i forgot a vital piece of infornmation.
The hosting application hangs when this problem occurs. I implement the Dispose( bool ) method for just this issue, but it never gets to a point where that would be feasible. It appears, at first glance, that the framework is looking for all the threads owned by the hosting app to finish as its trigger for releasing the dynamic config listeners.
It becomes a catch-22, it won't call Close until all threads complete, but I can't know to complete my thread without Close being called. :P
Ugh - I really don't want to require explicit addition and closure of this tracelistener, even though it would be understandable concidering the purpose and goal of this specific listener implementation.
|
|
|
|
|
Cromwell wrote:
I implement the Dispose( bool )
That looks somewhat suspicious to me. The IDisposable interface only has Dispose() as a member. If you are not implementing the actual members of IDisposable, give that a try first.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
True, i haven't implementing the raw Dispose() yet. I'll give it a try, but i'm not holding out hope.
Dispose( bool ) is the de-facto method for classes that have finalizers and is implemented by a number of classes, including the TraceListener base class.
|
|
|
|
|
yup - can't override the TraceListener.Dispose method. You have to override the Dispose( bool ) method which i've done and had no luck with. Stupid Dispose!
|
|
|
|
|
OK - So I figured out a solution, but I have to determine the impact. The worker thread IsBackground property had been set to false, mainly to increase performance. (This is supposed to be part of a high-performance, low impact auditing framework we are writing) I'm going to make the assumption that the Trace framework, waits for all non-background threads to complete before calling close.
Thanks for the help...
|
|
|
|
|
Glad you found a solution, but I still question the Dispose use. Have you actually put a " : IDisposable" at the end of your class definition? If not, you can do that and then supply at minumum an IDisposable.Dispose() implementation. This will be separate from any dependency upon being able to inherit from TraceListener, but you may need to call the base.Dispose() method to properly clean things up.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|