|
Add an event handler to SubItemClicked. Access an item's text using this:
this.listviewObject.Items[itemIndex].SubItems[subItemIndex].Text
Kuphryn
|
|
|
|
|
There is no SubItemClicked event for either the ListView or any other class in the .NET Framework Class Library. Perhaps for a third-party control, but not for System.Windows.Forms.ListView, System.Windows.Forms .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello. I need to show a message in a Windows Forms application. I was thinking in a ListBox.
I did some tests and I know how to show the message in a Console application. Just doint:
public class Message: MarshalByRefObject
{
public void Show(string s)
{
Console.WriteLine(s);
}
}
That works because it's easy to write in the standard output. The doubt is how to write in a component.
Can you help me?
Regards,
Diego F.
|
|
|
|
|
What exactly are you trying to do and where do you want this message displayed? If your remoting object is hosted by a console application with a loop to keep it from terminating, you can use the Console class at any time anywhere in your code, but it will be output on the remote host (i.e., server).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
What I need is a Windows Application that is continuously running and receiving messages. I want to show these messages in a ListBox. My question is how can I write the remote object to show the messages in a ListBox.
I told about the Console because I tried it first with a Console Application, but I'd rather prefer using a Windows app.
Regards,
Diego F.
|
|
|
|
|
Then every time your remote object's method gets call add a new item to the ListBox . Your remote object will need a reference to the ListBox in order to do so, so when your application instantiates the object, pass an instance of the ListBox to its constructor or assign it to a variable.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The problem with that is that the remote method is called from a Web Service and it can't serialize Windows Forms components. Isn't possible any workaround? My idea was just passing the string.
|
|
|
|
|
Yes, just pass the string but your remote method - the implementation on the server - adds that string as a new ListBox item. That's what I've been trying to say all along. Your Web Service (or whatever client) is making remote calls on your remoting object. That remoting object is the actual implementation and can do about whatever it needs to.
If you were writing a monitor application, for example, your Web Service will call the remote method passing a string. Your remote object's implementation of that method takes that string and adds it to a ListBox in your monitoring application, which needs to pass a reference to the ListBox when it registers the WKO (your remote object).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Just one more doubt.
How do I pass the reference of the ListBox?
I have this:
- The DLL that has the remoting object. That object has a ListBox and a method that adds a string to the ListBox (this is the method called by the web service)
- The web service that has an instance of the remoting class (static)
- The application that receives the messages with the listBox. This application has an instance of the remote object.
- The client application that calls the web method.
This doesn't work because the two remote objects created are not the same, I guess. I tried to write a web method that receives a remote object to use that object, but I get an error.
How can I do that?
I'm finding too much problems here. Maybe I should use a console application instead
|
|
|
|
|
The Remoting object should, for example, accept a ListBox as a parameter in its constructor. When your application that displays the ListBox loads, instantiate the Remoting object passing an instance of the ListBox to which messages are added. You then programmatically register the Remoting object as a WKO, which is discussed in the .NET Remoting documentation in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm sorry but I can't make it work. I tried to follow your instructions:
1) I have the remote object:
public class MessageWin: MarshalByRefObject
{
private string message= "Waiting messages...";
private ListBox l= new ListBox();
public ListBox L
{
set { l = value; }
get { return l;}
}
public string Message
{
get { return message;}
set { message = value;}
}
public void addMessage(string m)
{
mensaje = m;
l.Items.Add(message);
}
}
2) In the client app that should show the messages, just a blank form where I add:
public class Form : System.Windows.Forms.Form
{
private static MessageWin message = new MessageWin(); private System.Windows.Forms.ListBox listBox;
public Form()
{
InitializeComponent();
TcpServerChannel canal = new TcpServerChannel(8989);
ChannelServices.RegisterChannel(canal);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(MessageWin),"MessageWin",WellKnownObjectMode.Singleton);
}
// I drag a ListBox from the IDE and change that lines:
private void InitializeComponent()
{
this.listBox = message.L;
[...]
3) In the web service I have that:
public class ServRest : System.Web.Services.WebService
{
private static MessageWin m = new MessageWin();
private void RegisterChannel()
{
TcpClientChannel channel = new TcpClientChannel();
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownClientType(typeof(MessageWin), "tcp://localhost:8989/MessageWin");
}
[WebMethod]
public void sendMessage(string s)
{
m.addMessage(s);
}
4) Just another application that calls the sendMessage web method.
The application doesn't break but no messages are shown in the listBox. I guess the two remote objects are not the same. I tried passing the object to the web service but then I have problems adding the web reference...
Can you help me?
|
|
|
|
|
Again, your remote object class does not instantiate the ListBox but gets a reference to one instantiated and hosted by the Windows Forms application. If the remote object instantiates the ListBox itself, it can't post messages to the one in the Windows Forms application. It's a simple case of control references. You also can't host the ListBox you're incorrectly instantiating in your remote object because it would potentially run on a different thread and you can't add controls created on a different thread to your Form (or other container) when they were created on a different thread.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you for keeping helping me.
I don't understand your post. You say that my remote class gets a reference from the Windows forms application, but the code I posted before shows that the remote class creates a new ListBox and the Windows Forms app just gets the remote class one: listBox = message.L;
I think the problem comes because in the web service I declare a new remote object, different from the Windows application one.
What part of my code would you change?
|
|
|
|
|
Yes, the remote object should get an instance of the ListBox declared and initialized in the Windows Forms application. As I mentioned before, if you use the ListBox from the remote object, you could very easily run into many problems since the remote object would be created on a different thread depending on the activation type. Controls cannot host other controls created in a different thread and often times even calling methods or getting/setting properties on controls created in different threads causes problems, which is why Control.Invoke and Control.InvokeRequired exist.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
OK, but I still have the problem. I have 3 applications. I changed my code to pass the ListBox to the remote object, but my web service also needs a remoting object. If I declare a new remote object in the web service, I have two different objects, and I need to work with the same one.
How can I do that? What do I have to change in the web service?
|
|
|
|
|
This is a very simple problem that you're making way to hard and making me repeat myself far too many times.
The remote object is hosted by the monitor application (or whatever it is). It IS the implementation. All other remoting clients - like your web service - simply proxy calls to the remoting object that adds strings to the ListBox declared and instantiated in your Windows Forms application. That application is what is hosting the remoting object. The web service - or any client app using the proxy - doesn't need to have a ListBox at all. It proxies calls to the remoting object via a shared interface or a generated proxy using soapsuds.exe or something. There's absolutely no reason to host the remoting object implementation separate from your monitor application.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It's finally solved
I am really sorry. I was making a concept error. As I said, I was declaring two remote objects. I was watching Remoting samples and that was wrong.
As you said, I only have to declare the remote object in the monitor, and send the ListBox, that is declared in the windows form app.
Then, in the web service I just get the object from the channel with the Activator.GetObject method.
Now I see my messages.
Thank you for your help.
|
|
|
|
|
Hi,
Can I use window.showmodal?
Sombody help me?
|
|
|
|
|
You mean Form.ShowDialog ? Yes, but you must dispose the Form when you don't need it anymore. Modal dialogs need to be disposed explicitly or you'll gradually consume more and more memory that won't be reclaimed because of native resources:
using (MyForm form = new MyForm())
{
form.ShowDialog();
} Using using this way ensures that even if an exception is thrown your modal form is disposed. See the .NET Framework SDK for the Form.ShowDialog method for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you for ask,
Sorry, but,
I need to know Who can i use "window.showmodal" in web appl.
|
|
|
|
|
Then you should be more specific about what you need. This question doesn't belong in this forum. Ask in the Web Development[^] forum.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for your amiability and your time.
|
|
|
|
|
Hi all,
im having a small problem using an imagelist with a treeview. the problem is basically as follows. I add an imagelist and populate it with images (16x16 32bit) and i bind the imagelist to a treeview. so far so good, now if i add nodes to the treeview in code/designer time for a short while its ok, but after a while (a few compiles) the imagelist seems to break and the treeview nodes appear to have "blank" image.
The only way i can fix this is to manually delete the treeview and add it again with the imagelist.
Has anyone got a more practical solution to my problem?
many thanks,
Will
|
|
|
|
|
When you use the designer to add an ImageList , that ImageList is serialized to your .ResX file, which VS.NET uses by default (it's hidden; click Project-<Show All Files). There is a known issue where this can get corrupted. The solution is to remove the .ResX file - not your TreeView component - and re-add a .ResX file and then your ImageList . Your image indexes for the TreeNode s will still be correct so adding the new ImageList with images in the same indices will save you a lot of work.
This should be fixed in VS.NET 2005.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ive been asked to create a profile tool that interfaces with msn. It uses the events generated by msn to build up a users profile. What language would people recommend I use, and reasoning. Ive seen this dotMSN libary in C#. would people say this is the best way to go about this task??
any suggestions greatly appreciated.
mikey
|
|
|
|