|
Sorry, confused ListBox and ListView :-P
I think the current technique is to derive a class from ListViewItem and use that, so...
public class ProcessListViewItem : ListViewItem
{
public readonly Process Process;
public ProcessListViewItem(Process p) : this(p.ProcessName)
{
Process = p;
}
} Now the Add method will work when you pass in an instance of this new list view item
Process [] Processes = Process.GetProcesses();
foreach( Process p in Processes )
{
myListView.Items.Add( new ProcessListViewItem(p) );
} Then when you want to get the underlying process object you just cast the ListViewItem returned from the Items collection back to the ProcessListViewItem and access the Process property.
HTH,
James
Simplicity Rules!
|
|
|
|
|
Or you can just drop the Process object into the ListViewItem.Tag property...
i.e. LVITEM.lParam .NET style.
|
|
|
|
|
Doh! Obvious choice too, damn VB has me thinking that Tag is a string
James
Simplicity Rules!
|
|
|
|
|
James T. Johnson wrote:
damn VB has me thinking that Tag is a string
It's been a long time since I have bothered with VB, but as I remember it, it has a tendency of doing that...
Regards
|
|
|
|
|
After working in C# for so long I wasn't paying attention one day when I started to write a quick MFC app and I wound up writing this.
CSettingsDialog dlg = new CSettingsDialog();
dlg.ShowDialog();
} For those that haven't learned C++ yet I made 3 errors
1) dlg should be a pointer
2) it should be dlg->DoModal();
3) I forgot delete dlg;
Took me all of 30 seconds to realize why my code wasn't compiling
James
Simplicity Rules!
|
|
|
|
|
No, You made 4 errors...
4. If it is a simple modal dialog, You should just have decared it as a stack variable in the first place. No pointer, no delete, no worries...
|
|
|
|
|
I forget what it was for now, but there was some reason I had that. I wonder if Colin remembers the code
James
Simplicity Rules!
|
|
|
|
|
It's cool, When I first stepped into C#, I kept having Java flashbacks and use non-existant classes like StringBuffer and StringTokenizer.
Cheers
|
|
|
|
|
Hello..i used a listview to view the current processes in my Computer..but when i tryed to make any operations on these processes i couldn't ..i donnno how to convert the list items into objects of other class to perform these operations (im my case the System.diagnostics.process class)
here's my code :
private void Form1_Load(object sender, System.EventArgs e)
{
Process[]MyProcArray=Process.GetProcesses ();
foreach (Process MyProc in MyProcArray)
{this.ProcessesList .Items .Add (MyProc.ProcessName );
}
|
|
|
|
|
The problem you are seeing is because you are only adding the string which represents the process name to the list view, instead you need to add the Process object itself.
private void Form1_Load(object sender, System.EventArgs e)
{
Process[] MyProcArray = Process.GetProcesses();
foreach (Process MyProc in MyProcArray)
{
ProcessesList.Items.Add(MyProc);
}
} HTH,
James
Simplicity Rules!
|
|
|
|
|
I wanna check for pressing arrow keys in KeyPress event.
How can I do it?
Thanks
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
I think you can do something like this
if(e.KeyCode == Keys.Right)
{
DoSomething.....
}
|
|
|
|
|
Thanks
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
ez2 wrote:
if(e.KeyCode == Keys.Right)
Sorry,It doesn't exist in System.Windows.Forms.KeyPressEventArgs ,So How can I use it?
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
mazdak,
I just checked and your right. It looks as though keyPressEventArgs only handles characters (i.e. e.KeyChar returns a char) and not other keys like ALT, Arrows, etc. Not sure why that is so I will do some checking.
Alternatively, you could use the Keydown event which does have a KeyEventArgs and you can trap additional keys. In that case,
if(e.KeyCode == Keys.Right) should work.
I need some clarification myself on keydown vs. keypress anyway so I will let you know what I find.
|
|
|
|
|
jap - thats the way it goes.
keypressed is somewhat focussing on characters (in fact, the type of the KeyChar-property is char)
special keys (like arrows/functionkeys/etc.) you can only handle using keyup/keydown (the KeyCode-property in there is of the Keys type)
:wq
|
|
|
|
|
I try to connect to a password secured database, with oledbdataadapter
and I use the following connection string :
@"Provider=Microsoft.Jet.OLEDB.4.0;User ID = admin;Password=""123"";Data Source=F:\Mehdi\C#\Source Code\Filing System Manager\Sample.mdb;"
then I get the following error :
---------------------------
Microsoft Data Link Error
---------------------------
Test connection failed because of an error in initializing provider. Cannot start your application. The workgroup information file is missing or opened exclusively by another user.
---------------------------
OK
---------------------------
I would really apreciate an advise on this case
thanks
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
I was receiving the same error when I was looking at this for you the first time.
I came up with the following solution (As stated in MSDN).
Change the following registry key to point to your .mdw security file.
\HKEY_LOCAL_MACHINE\Software\Microsoft\Jet\4.0\Engines\SystemDB
I thought it was a bit of a hack, but I found enough documentation (in MSDN) that kept repeating it, so I tried it, and it works...
There has to be a better way...
Regards
|
|
|
|
|
Just found the better way...
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Peon;Password=PeonPassword;Data Source=C:\MyPath\SomeDatabase.mdb;Jet OLEDB:System database=C:\MyPath\MySecurityDatabase.mdw";
Regards
|
|
|
|
|
Thank you Neil,Now I'm not at place to check it but I'll do it as soos as possible.
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
Hi neil,
Thanks for the help, it solved my problem.. well almost !!!
Now I get this error message (It's because of the username and password of the mdb file, ichecked it )
with the right username and password it gives the same thing !
---------------------------
---------------------------
Index #0
Message: Not a valid account name or password.
Native: -124585838
Source: Microsoft JET Database Engine
SQL: 3029
---------------------------
OK
---------------------------
It's really getting on my nerves
I wonder if u could solve this problem, too.
thanks
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
My passwords work , Sorry...
I did notice your connection string had quotes (in the root of this thread) around the password, get rid of those...
Regards
|
|
|
|
|
I put a WAVE file into the resource as a Embedded resource. How to play it now? Could someone give me an example?
|
|
|
|
|
Since there isn't any managed methods for playing sounds you'll have to load the file from the stream into memory, then call the appropriate API function to do the actual playing.
To get the stream this should work.
public byte[] GetWave(string filename)
{
Assembly asm = GetType().Assembly;
Stream stream = asm.GetManifestResourceStream(filename);
byte [] wav = new byte[stream.Length];
stream.Read(wav, 0, wav.Length);
return wav;
} Untested but it should work since I wrote almsot the exact same code in another program.
I'm not familiar with the sound playing API though so you'll have to reference that on your own.
James
Simplicity Rules!
|
|
|
|
|
Thanks, but does anyone knows how to open these wave bytes??? I know that there's an API function called PlaySound, but it can play from file or from *Win32* resource. As far as I'm concerned C# doesn't compile resources as a Win32 type, but as it own format... Any ideas?
|
|
|
|