|
Hi, I am a an absolute novice to C# and have just about managed to get my first(simple) project off the ground. I am now trying to populate a listiew on a form from data retreived from Sql server in another class but I just get the message The listview does not exist in the class or namespace.
If I place the code in the form it works but not in a different class can some help please?
regards
kenwen
|
|
|
|
|
The ListView control has to be placed on a form. The class for the form is therefore aware of the existence of the control. This is why you can write code that references the control in the form's code-behind file. However other classes you create don't know anything about the ListView control unless you pass an object reference to it in one of its properties or methods.
I'm not sure what you are trying to do. Perhaps if you posted a bit of your code your requirements might make more sense.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Thanks Paul, Here is the bit of code that opens SQL and the recordset
using System;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace LoomScheduler
{
///
/// Summary description for LoadLooms.
///
public class LoadLooms
{
private System.Data.SqlClient.SqlDataReader SqlReader;
public LoadLooms()
{
SqlConnection myConnection = new SqlConnection("user id=username; password=sa;" +
"server=Brintons_NT03; Trusted_Connection=yes; database=LoomSchedules; connection timeout=30");
SqlCommand LoadLooms = new SqlCommand("Select LoomNo, Type," +
"ShortType From tblLoomMastShortVersion Where Plant = '12'" +
"Order By ShortType, LoomNo",
myConnection );
cnSchedule.Open();
SqlReader = LoadLooms.ExecuteReader();
while(SqlReader.Read())
{
ListViewItem lvi = new ListViewItem();
lvi.Text = (SqlReader["LoomNo"].ToString());
// Here I want to add each record to a listview called lvTopLooms on a form called frmMain
//lvTopLooms Items.Add(lvi.Text);
}
}
}
}
|
|
|
|
|
As I previously explained, you need to pass a reference to your ListView control to your class. Change the declaration of your constructor to:
public LoadLooms(ListView lvTopLooms)
and pass a reference to your control from the code in your form that instantiates LoadLooms .
Your code looks a bit odd though. I'm don't think it's good practice to pass references to controls around to other classes. It would probably be better if your class simply provided a method to retrieve data from your database. Your form class could then call this method to get the data to populate the ListView control and you would'nt have to pass a reference to this control anywhere. Also, you're doing stuff in the class constructor that would be better suited to being placed in a method. The class constructor should really only be used for the initialization of variables, resources etc.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Thanks Paul,
I think I see how it works also thanks for the other tips
Kenwen
|
|
|
|
|
when it release ?
(not the beta or the expres)
|
|
|
|
|
I currently sell the beta and express versions for a astronomicalreasonable fee. The full versions are available from Microsoft.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
Right now, only for MSDN subscribers to download, I thought.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Did they stop selling MSDN subscriptions? :p
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
LOL - no, but the OP I reckon wants to buy a box with the VS2008 DVDs, posters, etc, not necessarily a full MSDN sub so he can download it.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
If you don't want a full (and expensive!) MSDN subscription, then there will be online retailers who are authorised to sell VS2008 - Amazon, for example, can sell you a boxed copy of VS2005 at the moment, and I'd think the same will be true of VS2008.
"On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't.
"I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it."
-Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.
|
|
|
|
|
Hello everyone,
I am using WebBrowser Control and when I check all the supported properties, methods, and events associated with the WebBrowser and InternetExplorer objects; I don't see anything that can be used to catch the HTTP requests!
I am able to get the URL address for a website using DocumentComplete (Fires when a document is completely loaded and initialized) or get the Client Entered information such as username, password and so on using BeforeNavigate2 (Fires before navigation occurs in the given object.
My undrestanding is that for every object such as images a HTTP request is sent to the server. Then the question is how can I get/monitor all these requests?
Any information on this is greatly appriciated. Thank you and have a great day.
Khoramdin
|
|
|
|
|
Khoramdin wrote: My undrestanding is that for every object such as images a HTTP request is sent to the server. Then the question is how can I get/monitor all these requests?
Using the properties and methods exposed by the WebBrowser control - you don't. It doesn't fire these events on an object-by-object basis. They only work on a page-by-page basis.
If you want to capture all of this stuff, you'll need to build yourself a proxy server to capture it. All the request, object-by-object, will go through the proxy.
|
|
|
|
|
Hello david,
Thank you for your reply. I am also wroking on a HTTP Sniffer which and after I create a socket using the Socket class as following:
mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
After I receive the packets, I try to analyze it by first placing the packet in memory.
The packets are sorted based on thier ProtocalType into TCP, UDP and I am able to get information such as Version, HeaderLength, TotalLength, and so on for both the protocals.
My question is where should I look to get the URL address of the HTTP requests? If I am not mistaken the information should be available in HTTP Header rather than IP Header, TCP Header, or UDP Header!
Am I on the right track or I am way off and need to re-think this? Any information on this, is grealy appriciated Dave. As always, thank you so much for your help and have a wonderful day.
Khoramddin
|
|
|
|
|
Wow. You've gone from simply using a WebBrowser control to writing your own sniffer in one post.
Khoramdin wrote: My question is where should I look to get the URL address of the HTTP requests?
None of the headers will contain this. It'll be in the TCP packet data. You may have to string multiple packets together to get the entire request URL.
|
|
|
|
|
No, I started the work on BHO and then when I couldn't get the HTTP request moved to HTTP Sniffer. Then I heard from someone that I should be able to capture the HTTP requests using the BHO and that is why I thought to come and ask since when I looked for information about that, I could not find any. I wish I was that clever, mate!
The HTTP sniffer that I managed to put together is based on many articles that I found online such as http://www.c-sharpcorner.com/UploadFile/leonidmolochniy/SimpleSnifferInCS11222005232804PM/SimpleSnifferInCS.aspx[^]
Regarding what you said about URL address in TCP. If each packet doesn't hold all the information the how do they know where to start and where to end regarding the connection and file transformation?
Thank you,
Khoramdin
|
|
|
|
|
TCP is the transport protocol. It doesn't have anything to do with actually making the request. All it does is make sure that the "request message" makes it to the destination IP. If the message is too big for a single packet, the message is broken up into multiple packets until the entire message is sent. It's up to the receiving side to rebuild the message using all of the packets involved in it. TCP makes every attempt to get the entire message to the destination and get the packets reassembled in the correct order.
HTTP is the messaging protocol. This is what is making the requests and processing the returned data. It doesn't care that TCP is carrying the message. If you were so inclined, you could transport the request and response messages on SneakerNet and floppies if you built the correct drivers for it on each end of the connection.
Khoramdin wrote: how do they know where to start and where to end regarding the connection and file transformation?
By interpreting the data in each TCP packet. You have to have an in-depth knowledge of HTTP to do this.
|
|
|
|
|
Hi,
How can I read data from a COM port?
Best wishes
|
|
|
|
|
|
Do any of these articles help?
/ravi
|
|
|
|
|
I am having a problem with a timer in my program. I am sure I am missing serveral things that someone else will see easly.
this is a short example of my code.
private void button_click_1(object sender, eventargs e)<br />
{<br />
starttimer();<br />
Dothewhile();<br />
}<br />
<br />
public void starttimer()<br />
{<br />
timer1.start();<br />
timer1.interval = 1000;<br />
}<br />
private void timer1_Tick(object sender, EventArgs e)<br />
{<br />
MessageBox.Show("hello");<br />
}<br />
public void Dothewhile()<br />
{<br />
while (Run == true)<br />
{<br />
}<br />
}<br />
<br />
I am assuming the while statment is over taking the timer event and i just cant see when the timer hits but dont know for sure because i am stupid. But i would like to have some input on the ideal why the timer is never seen unless i turn the while statement off.
thanks danzar
Superman was my hero till he got a real job.
|
|
|
|
|
You are using a System.Windows.Forms timer, which ALWAYS runs on the main GUI thread. Therefore, your timer1_Tick method is waiting for the main thread to become available, which only happens when you exit the while loop. If you want to receive the Tick event in a separate thread (which you indicate is the desire from your post), then use either System.Timers.Timer or System.Threading.Timer, or start your method DoTheWhile in a new thread, which will free your main GUI thread for the timer.
Jeff
|
|
|
|
|
Perfect. thank you very much. this was exactly what i needed to know and a explaintion on why it wasnt working..
Thank you again!
|
|
|
|
|
danzar wrote: I am assuming the while statment is over taking the timer event
#1 Don't make assumptions.
#2 Don't make up terminology in text based communications ( over taking the timer ) because your readers won't know what you are talking about.
|
|
|
|
|
led mike wrote: danzar wrote:
I am assuming the while statment is over taking the timer event
#1 Don't make assumptions.
I know its a bad habbit I have. sorry
led mike wrote: #2 Don't make up terminology in text based communications ( over taking the timer ) because your readers won't know what you are talking about.
My poor choice of words, was from the lack of not knowing the correct terminolgy for the issuse I was having. I know now that I was wrong in my description of the issuse I was having. Sorry again for the mistake but was the result of learning.
A wise man said- You never learn unless you ask for help.
|
|
|
|