|
.SelectedIndices[0]
/ravi
|
|
|
|
|
Thanks, this works but when the first item in the listview is selected I get the following.
InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index
???
|
|
|
|
|
karl1701 wrote: InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index
That implies no item is selected. Try this (intentionally verbose) example:
int GetFirstSelectedItem
(ListView theListView)
{
int nIndexOfFirstSelectedItem = -1;
SelectedListViewItemCollection selectedItems = theListView.SelectedItems;
if (selectedItems.Count > 0) {
ListViewItem firstSelectedItem = selectedItems[0];
nIndexOfFirstSelectedItem = firstSelectedItem.Index;
}
return nIndexOfFirstSelectedItem;
} /ravi
|
|
|
|
|
Thanks, it seems that the problem was I was checking the index when the SelectedIndexChanged was fired. Whenever I made another selection I would receive the error. I switched the code to the Click event and now it works fine.
Thanks for your help
Karl
|
|
|
|
|
listView1.SelectedItems
-> listView1.SelectedItems[0].Index
^^ lg
|
|
|
|
|
Thanks, this works but when the first item in the listview is selected I get the following.
InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index
???
|
|
|
|
|
Hi every body ,
(sorry for my english...)
Suppose we have a text box (textBox1).
If we "leave" this text box by pressing the TAB key, the order of the following events is:
textBox1_Validated
textBox1_LostFocus
But, if we leave this text box using the mouse, that is by pressing on another control on the Form using the mouse, the order of these events is:
textBox1_LostFocus
textBox1_Validated
This is strange behavior in my opinion.
May anyone explain me this behavior?
Thanks in advanced, elaj
|
|
|
|
|
When you change the focus by using the keyboard, focus events occur in the following order:
- Enter
- GotFocus
- Leave
- Validating
- Validated
- LostFocus
When you change the focus by using the mouse or by calling the Focus method, focus events occur in the following order:
- Enter
- GotFocus
- LostFocus
- Leave
- Validating
- Validated
There is nothing strange in that, is it?
-- modified at 5:22 Monday 22nd January, 2007
SkyWalker
|
|
|
|
|
Hi SkyWalker,
There is nothing strange if your code does not depend on it.
However, i wrote a code that that register to control's "LostFocus" event and do some job there.
If the user call some other method - i unregister the event handler, but it should be done only after the "LostFocus" occurred.
Because the the user traditionally will call my method in the "Validate" event, you may understand why this behavior raise some problems.
However to overcome it i do the following:
I registered to the "GotFocus" event, and within this event handler i registered to the "LostFocus" event.
When the "LostFocus" event occurred, i do my job and unregistered the handler when it completed.
Elaj
|
|
|
|
|
ok
SkyWalker
|
|
|
|
|
I have a simple question with no doubt a complex answer. What I am trying to achieve is to check LAN for machines (mostly Workstations but could be windows xxxx Servers among them and find which ones are running a particular Service.
Is there a relatively easy way of doing this? What sort of security measures could get in the way? The service I'll be searching for will does export a remoting interface.
Any pointers would be greatly appreciated.
Happy programming!!
|
|
|
|
|
One way could be using
<br />
[DllImport("MPR.dll")]<br />
public static extern UInt32 WNetEnumResource(IntPtr hEnum, ref Int32 lpcCount, IntPtr lpBuffer, ref UInt32 lpBufferSize);
Some code example[^]
SkyWalker
|
|
|
|
|
When you design a form in Visual Studio 2005, you may put a control in form and set properties of this control. After you did this, Visual Studio will insert codes to XXX.designer.cs automatically. Even the control is a Third-Part control, Visual Studio can do the same thing.
So, my question is how to do the thing by ourselves ?
|
|
|
|
|
By not doing it in the designer. If you want to control the property completely, create it in your form's load event, and add it to the forms Controls collection.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
You can write the code by yourself.. declare objects and initialize them in InitializeComponent() (run the method in constructor) if you want them to be available at design time or in OnLoad event if you want them to be created at runtime.
vs designer uses *.designer.cs files (and keyword 'partial') to separate it's code from yours. so the file isn't needed.
life is study!!!
|
|
|
|
|
SeishinLovesC# wrote: declare objects and initialize them in InitializeComponent()
NEVER add code to InitializeComponent, the IDE will change it on you without warning.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
true.. but otherwise they won't be available at design time..
life is study!!!
|
|
|
|
|
|
Is there a way to tell if the Code is running as a Windows App or Web? If so how?
|
|
|
|
|
Jeffrey Scott Flesher wrote: Is there a way to tell if the Code is running as a Windows App or Web?
Well, if it's running as a web app, then it's running on a server, not on a client. Any UI classes will have a different root. I don't see how this could ever come up, unless you're talking about controls that are hosted in a browser, not ASP.NET code ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I have a common library that runs in a Windows App and a web app; not controls; I was using pre-compile directives i.e. #if; but that's a bad work around since I have to recompile; I would think that there is a way to know what environment you are running in but I can't find it; I'm thinking about breaking out the code so that I have a Windows version and a Web version; but keeping them in sync is a nightmare.
|
|
|
|
|
Hi,
If your library is called in a web context you should be able to query for the System.Web.HttpContext.Current object. If running as the Windows app this code will throw a NullReferenceException (i.e. there is no HttpContext) so you could put this test in a try / catch block and set your environment based on the results of the test?
Admittedly that's pretty inelegant but I can't think of a better way. Any other suggestions?
HTH HN3
|
|
|
|
|
public static bool IsWindows
{
get
{
try
{
if (System.Web.HttpContext.Current == null)
{
return true;
}
}
catch
{
}
return false;
}
} // end IsWindows
Thanks it works better then anything else I tried; may not need to put it in a try; it seem to just be null in Windows; but I'm not sure about Mono so it's better than getting an error; but I still think there should be a function to do this; it seems like this is as basic as a function need to see what OS your running like IsMono.
|
|
|
|
|
Jeffrey Scott Flesher wrote: Is there a way to tell if the Code is running as a Windows App or Web?
Perhaps, but to give a good answer to that one should really need to know a bit more about why you are asking the question. If the code doesn't already know that, why would it care?
---
Year happy = new Year(2007);
|
|
|
|
|
I just posted answer seconds after you posted this (please read); in short in have a library of code (non-controls) that has logic that I use in both windows and web apps; the problem is that if I need to notify the user; or gather information; I need to know if I'm running in a Windows app or web app; pre-compilers (#if) are not a good solution since the main solution contains both Windows and Web app and I deploy them at the same time. It sounds odd that code should know what environment it is running; apps generally written for the web or windows; but when you have common libraries then the need is great and it seems that there should be a function to return that information without having to poke around with a hack like looking for folder names like "Program Files" or something even stupider; I have looked for this answer to no avail and my next step is to ask MS; which for a guy is like asking for directions when I'm lost; I have a map; just no clue as to what state I'm in.
|
|
|
|