|
This will remove the first selected item from the list view.
if (myListView.SelectedItems.Count > 0)
myListView.Items.Remove (myListView.SelectedItems[0]); /ravi
|
|
|
|
|
I think a javascript will help if you want it without reloading!
I was born dumb!!
Programming made me laugh !!!
--sid--
|
|
|
|
|
Ok here is the problem. I am developing a server in C and a client in C#. The server send streams of data to the client, and the client is responsible for decoding and interpreting these stream. So, if I send a simple "Hello world" from the server to the client, it works. If I send a byte representing an integer (I use memcpy) I can decode it in the client. But, the problems start when after some integers, I also put a string. If I put 2 bytes, each representing some number, I am still able to decode the string that follows using:
System.Text.Encoding.ASCII.GetString(buffer,2,length)
But if I say 3 bytes, and then the string, I don't get anything (yes, I said buffer,3,length to reflect the server changes), I get garbage.. Can anyone please help me? Thank you.
|
|
|
|
|
What kind of "garbage" do you get?
I think that we have to see some code in order to tell what's wrong with the code...
---
single minded; short sighted; long gone;
|
|
|
|
|
Okay then.
Here is the server
memcpy(msg,&type,1);
memcpy(msg+1,&nr,1);
memcpy(msg+2,&online,1);
memcpy(msg+3,&p,sizeof(p));
type is 2, nr is 4 online is 0 and p is "Hello world". And on the client I get some unrecognizable characters (those squares you sometimes get). BUT, when online is 1 the string stays in one piece.. What am I supposed to make of this?
|
|
|
|
|
if only you had shown the client code and the server code in one message...
and, if at all possible, the hex representation of these data bytes arriving at the client.
|
|
|
|
|
But I already showed more than enough. Since I am able to transmit messages between the server and the client THERE IS NO PROBLEM HERE. Anyway, the server uses fprintf and the client uses BeginReceive - EndReceive (IAsync bla bla).
The problem is the way I am handling the array of bytes coming from the server. I suspect EndReceive thinks that a 0 means \0 (as in end of string). So it stops there. I don't know why this happens..
|
|
|
|
|
nc3b wrote: But I already showed more than enough
Sorry for trying to help you.
Debug Rule #1: when the system does not perform as designed, at least one element is wrong,
and it could be anything; not a single assumption is beyond scrutiny.
|
|
|
|
|
nc3b wrote: But I already showed more than enough.
I haven't seen a single line of the code that recieves the message.
nc3b wrote: Since I am able to transmit messages between the server and the client THERE IS NO PROBLEM HERE.
Just because some code works in some cases doesn't automatically mean that it works in all cases.
nc3b wrote: I suspect EndReceive thinks that a 0 means \0 (as in end of string). So it stops there. I don't know why this happens..
I don't know why it happens either, as I don't know if you use BeginRecieve and EndRecieve correctly.
---
single minded; short sighted; long gone;
|
|
|
|
|
The thing is that it's a lot of code.. Anyways, let's see...
The BeginReceive
sock.BeginReceive(buffer,0,buffer.Length,SocketFlags.None,receive,_sock);
The EndReceive
int stop=_sock.EndReceive(result);
Is it not correct?
|
|
|
|
|
That code is correct, but I have no idea if the surrounding code is correct, so that the buffer, receive, _sock and result variables are correct.
---
single minded; short sighted; long gone;
|
|
|
|
|
I might as well archive the project and attach it But anyways. I don't mind
private System.Byte[] buffer=new Byte[1024];
private void SetupReceiveCallback(Socket _sock)
{
AsyncCallback receive=new AsyncCallback(OnReceive);
_sock.BeginReceive(buffer,0,buffer.Length,SocketFlags.None,receive,_sock);
}
private void OnReceive(IAsyncResult result)
{
try
{
Socket _sock=(Socket)result.AsyncState;
int stop=_sock.EndReceive(result);
String str=System.Text.Encoding.ASCII.GetString(buffer,0,stop);
MessageBox.Show(str);
process(buffer,stop);
SetupReceiveCallback(_sock);
}
catch
{
MessageBox.Show("Out");
this.Close();
}
}
So?
|
|
|
|
|
Hi Guys
Does anyone know an open source library for skinned windows controls written in C#?.
Thanks in advance
Mahmoud Zidan
|
|
|
|
|
I am trying to figure out how to list all user accounts that exist in the SAM. I have figured out how to get the account name of the owner of a file, but not a list of all accounts on the machine.
Thanks for helping.
|
|
|
|
|
You might want to take a look at this article[^].
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
My C# book reads:
In this example, the two-parameter constructor executes before any code in the body of the one-parameter constructor (though in this particular case, since there is no code in the body of the one-parameter con-structor, it makes no difference).
By following through the code it seems that the one-parameter constructor is called first, which in turn calls the two-parameter constructor, so, is this an error, or do you think it might have another meaning?
J.
using System;
using TestConsole.TestClasses;
namespace TestConsole.ConsoleCmds
{
public class TestOne
{
public static void Main()
{
Car myCar = new Car("Proton Persona");
}
}
}
namespace TestConsole.TestClasses
{
class Car
{
private string description;
private uint nWheels;
public Car(string model, uint nWheels)
{
this.description = description;
this.nWheels = nWheels;
}
public Car(string model) : this(model, 4) { }
}
}
Jon
|
|
|
|
|
Hi Jon,
it is the one-parm constructor that gets invoked first, but it is the body of
the 2-parm one that executes before the (empty) body of the 1-parm constructor.
Same prder as the code that says: Car(model) needs "this(model,4)" before it does the "{ }".
BTW if you use <pre>some code</pre> you can show code snippets
that preserve their formatting (mainly indentation). That would be much more readable.
On the other hand, if your post contains special characters (especially <)
they get eaten by the HTML interpreter, then you better would check the "ignore HTML tags"
checkbox below the textbox (but then thr pre command will no longer work either).
|
|
|
|
|
Thanks for your reply.... you mean this is readable?
class Car
{
private string description;
private uint nWheels;
public Car(string model, uint nWheels)
{
this.description = description;
this.nWheels = nWheels;
}
public Car(string model) : this(model, 4) { }
}
Jon
|
|
|
|
|
Hi Jon, you're welcome. Yes, it is much more readable like that.
|
|
|
|
|
Luc Pattyn wrote: if you use
some code you can show code snippets
that preserve their formatting
If I may add, I like to put <code> and </code> tags inside the <pre> tags. Just colors it up nice
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
I'll try that next time; I once did just <code> and was not happy about the result. Thanks.
|
|
|
|
|
<code> by itself doesn't do much, at least when it comes to preserving indentation.
Here is a simple example of how I do it...
private bool foo(int x)
{
if ( x < 0 )
return true;
else
return false;
}
I like it because it makes the code stand out a bit better.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Oh, it's a dark red color?
I made a test message with and without <code>, and I couldn't see any difference at all.
I made a screen dump and pasted in photoshop, where I could put them in different layers on top of each other so that I could flip between them and see exactly what the difference was, but there was no difference.
Or was it? Maybe there was a slight difference? I had to use the eyedropper to get the color of the text to tell what the difference was...
---
single minded; short sighted; long gone;
|
|
|
|
|
Are you using <code> before or after the <pre> tag? It will make a difference.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
The code tag is inside the pre tag.
---
single minded; short sighted; long gone;
|
|
|
|