|
There is a certification/resume forum. I think I took both exams, and I just used experience to pass them and not a book so I am not a help (except to tell you about the other forum).
Steve Maier, MCSD MCAD
|
|
|
|
|
Hi everyone,
I've been playing with the dataGridView control in C# now for a couple of days, and I've got most all of the functionality that I wanted out of it. One thing I am not able to solve as of yet though I could use some help on. I have a contextMenuStrip associated with my dataGridView control. The way it is working now is that the user has to left click in the cell first (which selects it), and then they right click, it brings up the contextMenuStrip, which allows them to do a couple of things with the data in the cell. I am wondering if there is a way that the user can move the mouse to the cell, right click, have it select that cell automatically, and then the contextMenuStrip that appears will work on the contents of that cell they just right-clicked on. Also, I am wondering if there is a way to disable the contextMenuStrip if they are not in a cell? (Currently, they can click anywhere on the datagrid, even in empty space where there are no rows, and the menu strip will show up there ... I would like the menustrip to only show up when they right click inside of a cell that has text in it).
Thanks much in advance!
|
|
|
|
|
|
ur program returns a value only if he enters the if statement!
u must return also something outside of the if...
Type it the right way!
|
|
|
|
|
Well, read the error. What if a NEVER equals b ? You need to return a default value outside your for each.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
I imagine he was as embarrased about his question as I have been in the past, but deleting it is just bad form. At least I can have a look back at some of my questions now and have a laugh at the odd sarcastic comment thrown!
Regards
Angel
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
i have five columns for example the first one is ColumnName how can i add in the cell from the first row for ColumnName a string like "Adrian"?
i have something like this
dataGridView1[0, 0] = (DataGridViewCell)"mumu";
Error 1 Cannot convert type 'string' to 'System.Windows.Forms.DataGridViewCell'
Actually what i am trying to do is too send a table from a web service to client application!
Thanks!
-- modified at 18:19 Saturday 17th June, 2006
|
|
|
|
|
i am using now data sets ...but when i log in from my windows application to my web service i get this error ..atention :p
"System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.\n at Service.AcordaNote() in c:\\Inetpub\\wwwroot\\marius\\App_Code\\Servicep.cs:line 216\n --- End of inner exception stack trace ---"}
i am using sessions
this line 216 ,but i dont think this the problem
if ((bool)Session["loggedp"] == true)
but when i invoke the method from the web service .net test page it returns an xml document with no erors !
WHY?
pls help it is very urgent!
-- modified at 19:53 Saturday 17th June, 2006
|
|
|
|
|
Hi
Not sure how to explain this, but here goes. I have a method 'ShowFormForLong' which recieves a long as a parameter. It checks a Dictionary to see if the dictionary contains the long as a key. If it does, the object stored is a form, and the form is 'shown'. If the dictionary doesn't contain the long, a new form is created and added to the dictionary, and shown. Works a treat when the long is entered by the user, they press 'Go' button, and the onButton event calls the ShowFormForLong method.
But...and there always is a but....my app allows sockets to connect, and the socket can recieve a 'long'. I read a long from the socket, and fire an event, which my main form subscribes to. The eventargs contain the 'long' and I call 'ShowFormForLong' passing the long from the eventarg. But this time, the form is shown, but it seems as though the message loop isn't running in the form, as only the background is drawn, no controls are visible, and then the app crashes.
I will get the code on Monday, and post if nobody has any ideas, but is there something I should be doing? Or is it something as simple as I can't create multiple forms...
From memory...
Dictionary< long , MyFormClass>formDictionary;
void ShowFormForLong( long myLong )
{
if (formDictionary.Contains(myLong))
{
MyFormClass myForm = (MyFormClass)formDictionary[myLong];
myForm.Show();
}
else
{
MyFormClass myForm = new MyFormClass();
formDictionary.Add( myLong , myForm );
myForm.Show();
}
}
Regards
Angel
*********************************************
The sooner you fall behind, the longer you have to catch up.
-- modified at 16:05 Saturday 17th June, 2006 - typos
|
|
|
|
|
Angel1058 wrote: But this time, the form is shown, but it seems as though the message loop isn't running in the form, as only the background is drawn, no controls are visible, and then the app crashes.
Do you know when the crash happens, the long you got from the socket matches an existing one in the dictionary, or is a new one added to the dictionary? Or it crashes in both cases?
- It's easier to make than to correct a mistake.
|
|
|
|
|
hi Jun
It crashes in the show with a CLR exceptino - Unhandling exception of type "System Exception" occurred in Unknown Module or something like that. The long can exist or not, crashes on both cases, but I think Roberts suggestion below is the answer - cross threading!!
I love this place. New to C# / .NET. Good at C++ and MFC, but this CLR is all good stuff!!
Thanks for your time anyway, much appreciated
Regards
Angel
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
Not sure on this but may the event coming from the socket connection be called from a different thread then the GUI was created on. If yes use Control.Invoke to transfer the call to the appropriate thread.
|
|
|
|
|
Yes it is, the app listens to the socket on its own thread, so the user can do what they want without the app blocking on the receive (not up to async sockets yet!!). So, that could well be the problem. Haven't come across Control.Invoke, so off to google now.
Thanks to both of you for answering. I will post back with the results.
Regards
Angel
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
Hi
Just been messing with some code - the main application form (which created the second forms based on the 'long' is in thread 1 . I output Thread.CurrentThread.GetHashCode just before the second form is displayed to determine this.
When the socket event is fired, the thread is now Thread 3 . This is where it gets confusing. Calling a method on the main from (created from thread 1 ) from thread 1 , works, and creates the second form a treat. Calling a method from the main form (created from thread 1 ) from thread 3 , fails, and the second form doesn't work.
Is this what you're saying? I should only call methods from the main form, from thread 1 ?
I've looked at Invoke, but not got a clue how to use it with events.
If you can confirm the above I will go away relatively happy and know what the problem is.
Cheers
Regards
Angel
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
Yes that is what I mean. Its generally unsafe to change GUI elements from another thread than they were created in. Like in your case this will normally not result in an immediate exception but some weird behaviour. This even depends on which OS you are using.
The following snippet will demonstrate how to use Invoke with the standard EventHandler signature:
private void OnEvent(object sender, EventArgs e)
{
if (base.InvokeRequired) {
base.Invoke(new EventHandler(OnEvent),
new object[] {sender, e});
}
else
{
}
}
A bit of explanation:
InvokeRequired just checks if the current thread is the one the form was created in or not. Invoke will then transfer the call over the thread boundaries. Thus this function (when called from a different thread) will call itself again within the correct thread. Note that this call may block if the GUI thread is busy and wait till its free. You could also use BeginInvoke. Then the call would not block while the GUI thread is busy and the thread could keep running. The call would than be made the next time the GUI thread is free.
|
|
|
|
|
Blinding answer Robert - thanks.
This fixed the problem a treat, only to highlight a second problem (with similar results). When the 'long' comes in via socket, I fire an event. The main form subscribes to display the second form (discussed above), but so does another form, which the user can enter a long manually to keep the app in sync. Unfortunately, when I update the long on the users form with the long from the socket, an event gets fired which creates the second form. So, when a socket long arrives, two separate evenhandlers attempt to create the second form.....hmmm.
Needless to say, they don't now!!! But I'd have never have got there without the above code anyway.
Many thanks for your answer and your time. Much appreciated.
Regards
Angel
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
The problem is probably coming from the fact that the socket request is from a remote system and you cannot do a Show() across that boundary remote boundary. ( The exact same behaviour occurs if you setup a remote agent and call a method remotely that would show a form. )
Basically what you have to do is marshal the assembly across the boundaries so that the form is on the local machine and have the caller issue a CreateInstance and call Show() for this to work.
The reason it does not work is that your Show() opens up a message pump on your machine, the empty form opens up on the remote machine, the message pump on the remote machine issues an Activate only there is nothing on the remote machine listening for it on the message pump. Meanwhile your message pump is sitting there getting bored because it is not recieving any messages.
To start research on what it would take to make it work, read about MarshalByRefObject and then think about the impact of shipping Windows Forms all over the network when doing this.
|
|
|
|
|
No, the second thread is on the local machine. The remote machine is a console app, no gui. Just servers a stream of data as and when. Robert's answer about messing about with GUIs across different threads was the problem, but thanks for the info on remoting. I thought C# / .NET would be a walk in the park after 10+ years of C++ / MFC. It's no park! (Or possibly Central Park, NY after 2300 hrs).
Regards
Angel
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
Hi There
This has got to be an easy one... I am coming to ADO.NET from an ADO background, so i appologise if it comes across as totally stupid!
All i want to do is insert a new row into a table and pull back the autonumber primary key assigned to it.
What i don't want to have to do is:
1) Fill a Dataset in order to get a DataTable definition.
2) Use stored procedures.
Anybody know the answer off the top of their head? Guess i really need to buy a good ADO.NET book.
Thanks In Advance
Rich
|
|
|
|
|
You might get a faster answer if you post this question on the ADO.NET board instead of the C# board.
|
|
|
|
|
|
hello, this is my first post here
i want to create a mysql database connection on a remote machine with c#.
well i tried to work with the SqlDataAdapter to create a connection to my www site but it always says no connection possible
after looking for some tutorials i didnt found anything usefull and i hope someone here could help me out
to make it a bit more clearly - how do i connect?
thanks in advance and sry for my bad english
|
|
|
|
|
A more specific error message would be helpful...
Have you installed an OleDb connector for MySQL?
---
b { font-weight: normal; }
|
|
|
|
|
oh well i never did that before :->
first i made a new project, just dragged the SqlDataAdapter in my Design and then the Assistent popped up. i chosed "new connection" and entered the infos in the textboxes below.
the error that appeared was the following: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied (happens when i want to test the connection or pick a database on the server)
thats all what i did
|
|
|
|