Question MenuStrip Help

janu

Member
Joined
Jan 6, 2012
Messages
16
Programming Experience
Beginner
I am very happy to be the member of this forum .. I observed that I can learn here as I am New for Vb.Net..

My Ist question on this forum is :

I have a project based on web references

I have ComboBox added with two items by which the web service is called :

5mmycw.jpg



VB.NET:
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 ComboBox.Items.Add(New TargetServer("Product1", New Uri("https://www.*******************_id=7"), New Uri("https://www.*******************?WSDL")))
 ComboBox.Items.Add(New TargetServer("Product2", New Uri("https://www.*******************_id=9"), New Uri("https://*******************?WSDL")))
End Sub

How can I achieve same in MenuStrip Like this ..

141juir.jpg


Please help with code..
 
You don't put the same. That's the point. You're trying to take something simple and make it complex. Forget your TargetServer class. What do you want to do when the user clicks the menu item? That is what you put in the Click event handler. Just write a method that executes the request, pretty much as you have in your SelectedIndexChanged event handler from before. Now, in your Click event handler, call that method and simply pass the appropriate URLs.
 
You don't put the same. That's the point. You're trying to take something simple and make it complex. Forget your TargetServer class. What do you want to do when the user clicks the menu item? That is what you put in the Click event handler. Just write a method that executes the request, pretty much as you have in your SelectedIndexChanged event handler from before. Now, in your Click event handler, call that method and simply pass the appropriate URLs.

that is the question all about .. I started this thread inorder to get help regarding this issue only .. in click event handler how I pass appropriate uri.. please write one line of code to solve my problem. thanks in advance
 
You don't need me to write any code because you've already got the code. It's in your SelectedIndexChanged event handler. Simply move that code into its own method. Wherever you're using a TargetServer in that code, add a parameter instead. You then call the method from your Click event handler and pass the appropriate URLs to the parameters. Don't say that you don't know how to do that because you do. You can even do it step by step. You can move the code out of your SelectedindexChanged event into its owmn method, right?
 
You don't need me to write any code because you've already got the code. It's in your SelectedIndexChanged event handler. Simply move that code into its own method. Wherever you're using a TargetServer in that code, add a parameter instead. You then call the method from your Click event handler and pass the appropriate URLs to the parameters. Don't say that you don't know how to do that because you do. You can even do it step by step. You can move the code out of your SelectedindexChanged event into its owmn method, right?

SIR, If I would have that capability then there were no reason of making request on request..
 
So you're saying that you can't even take the code out of the SelectedIndexChanged event handler and put it into its own method?

OK what should I do with these highlighted codes
VB.NET:
_service.Url = DirectCast([COLOR=#ff0000][B]ComboBox.SelectedItem, TargetServer[/B][/COLOR]).ServiceUrl.ToString()             
Dim cc As New CookieContainer()             
Dim req As HttpWebRequest = DirectCast(WebRequest.Create(DirectCast([COLOR=#ff0000][B]ComboBox.SelectedItem, TargetServer[/B][/COLOR]).SessionNegotiationUrl), HttpWebRequest)             req.CookieContainer = cc             
req.BeginGetResponse(New AsyncCallback(AddressOf GetSessionId), req)         
End Sub
 
Exactly what I said earlier:
Wherever you're using a TargetServer in that code, add a parameter instead.
On the first line you use a TargetServer to get a URL. Instead, add a parameter to your method for that URL and use that parameter on that line instead. Do the same thing for the third line. Your method will now compile as is and when you call it, which you will do in the Click event handler of each menu item, you pass the appropriate URLs to those parameters.
 
Exactly what I said earlier:On the first line you use a TargetServer to get a URL. Instead, add a parameter to your method for that URL and use that parameter on that line instead. Do the same thing for the third line. Your method will now compile as is and when you call it, which you will do in the Click event handler of each menu item, you pass the appropriate URLs to those parameters.

add a parameter to your method for that URL and use that parameter on that line instead ?????????
really I don't know
 
I honestly don't understand how you can be at a point where you are using a WebRequest to download data and yet you don't know how to add a parameter to a method. This tells me that you have started trying to write applications to do specific things without actually learning the basics of programming in VB. If you don't know how to do things like declare properties and methods or write If statements and loops then you shouldn't even be thinking about doing things like using WebRequests. If you need to learn the basics then you should find a good beginners tutorial and work your way through it. This is a good one:

Microsoft Visual Basic .NET tutorials for Beginners

You may think that I'm just trying to be difficult but that is not the case. I'm trying to get you to think like a developer. If you aren't able to do that then you'll just have to keep asking simple questions over and over and never be able to do anything on your own. If you learn how to think the right way then you will be able to solve far more of your problems on your own. To that end, if I told you to write a method that had parameters for two String values and then displayed those values to the user, could you do it?
 
I honestly don't understand how you can be at a point where you are using a WebRequest to download data and yet you don't know how to add a parameter to a method. This tells me that you have started trying to write applications to do specific things without actually learning the basics of programming in VB. If you don't know how to do things like declare properties and methods or write If statements and loops then you shouldn't even be thinking about doing things like using WebRequests. If you need to learn the basics then you should find a good beginners tutorial and work your way through it. This is a good one:

Microsoft Visual Basic .NET tutorials for Beginners

You may think that I'm just trying to be difficult but that is not the case. I'm trying to get you to think like a developer. If you aren't able to do that then you'll just have to keep asking simple questions over and over and never be able to do anything on your own. If you learn how to think the right way then you will be able to solve far more of your problems on your own. To that end, if I told you to write a method that had parameters for two String values and then displayed those values to the user, could you do it?

thanks sir, i m trying my hard to learn vb.net .. and will keep going on .. but right now one line of your code will solve my problem .. keen request to you ..
 
Back
Top