|
hustler2005 wrote: I have tried looking in books but had no success.
Don't understand why. There is plenty of documentation, and you couldn't find anything?
sender is rather obvious, the sender of the event. EventArgs is the data generated from the event
only two letters away from being an asset
|
|
|
|
|
sorry, what i meant is "i have had no success" in understanding what i have read. if someone could explain it a lil more clear/easier to understand??
it would make my day!
Cheers
|
|
|
|
|
As Mark said, there is already a lot of information about this online.
Anyway, the sender parameter is an object representation of the control that caused the event to be sent. It is an object , which means that you need to have some knowledge of what the actual sender is supposed to be if you want to use it inside the event handler. In order to use the sender you need to cast it to the appropriate type. In the case of your example, you would need to do one of the following:
private void Form1_Load(object sender, System.EventArgs e)
{
Form f = sender as Form;
if (f != null)
{
}
} or
private void Form1_Load(object sender, System.EventArgs e)
{
Form f = (Form)sender;
} To me, the preferred way is the first one since it is a bit safer.
The e parameter represents the "EventArgs" of the event. In reality, EventArgs is a class that is used to hold the data generated by the event that could be used within the event handler. All events should use either the System.EventArgs class or a custom (derived) System.EventArgs class. The default System.EventArgs class maintains no data about the event.
|
|
|
|
|
Thanks Scott/Matt for your input.
You mention there is alot of documentation online, can you suggest a good starting point??
This would be very help indeed.
Cheers
|
|
|
|
|
|
Hi all,
I'm using the CellsPainting event to draw a bitmap for a particular header cell. Here is code that does this(the bitmap is in an imagelist).
//this.images is an ImageList with my bitmap
void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex == 1 && e.RowIndex == -1)
{
e.PaintBackground(e.ClipBounds, false);
Point pt = e.CellBounds.Location;// where you want the bitmap
in the cell
int offset = (e.CellBounds.Width -
this.images.ImageSize.Width) / 2;
pt.X += offset;
pt.Y += 1;
this.images.Draw(e.Graphics, pt, 0);
e.Handled = true;
}
}
I;m using the MOuseDown event to get the index of the right clicked column
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
DataGridView.HitTestInfo hit = dataGridView1.HitTest(e.X, e.Y);
poz = dataGridView1.Columns[hit.ColumnIndex].Index;
dataGridView1.CellPainting +=new DataGridViewCellPaintingEventHandler(dataGridView1_CellPainting);
}
}
My problem is that when reordering the columns the headerCell is going crazy. The header cell value, witch is a string(the column name) starts to have a strange behavior.
Is there anything I'm missing here please?
|
|
|
|
|
Hello, I need your help and guidance, I am feeling lost.
I have a tcp/ip socket server application that receives messages threw a router.
my hardware sits on wireless network, creating messages, and pushes them to a tunneling router than in it's time push the messages to a middleware PC
with a socket server program, listening for the data.
my problem is, when i disconnect the tunneling router and reconnect, the connection breaks, and I can't keep receiving messages from the router.
this causes an instability issue for me, since network crashes can happen, and I need my network to survive them.
what you think might be the problem?
How can I solve it?
any help will be most appreciated.
|
|
|
|
|
gizmokaka wrote: the connection breaks
What connection? I am not able to clearly understand your layout description.
|
|
|
|
|
OK from the top:
I have a wireless RF network in which I have units running and sending messages.
the receiving end for the messages is a tunneling router with one end RF receiver and the other has
TCP/IP port, and this tunneling router translates from one network to TCP/IP packets then it forwards
the messages to a PC that's running socket server application that listens constantly on a specific port, and when data is received it handles it.
when I say the connection breaks I mean, I disconnect the tunneling router from the network,
and reconnect it.
when it's reconnected it's no longer able to receive messages.
the thing is, if I disconnect the network cable it simply breaks with a message box
saying something about lost messages and stops receiving messages, but the program doesn't crash.
but if I disconnect it's power, it breaks with an exception
"An existing connection was forcibly closed by the remote host"
and stops the program.
of course I am talking of debug mode.
hope it's clearer now.
if my reply will be late, I am sorry, I promise to reply to every comment
tonight or tomorrow.
thanks again for your help.
|
|
|
|
|
gizmokaka wrote: OK from the top:
I have a wireless RF network in which I have units running and sending messages.
the receiving end for the messages is a tunneling router with one end RF receiver and the other has
TCP/IP port, and this tunneling router translates from one network to TCP/IP packets then it forwards
the messages to a PC that's running socket server application that listens constantly on a specific port, and when data is received it handles it.
gizmokaka wrote: I have a tcp/ip socket server application that receives messages threw a router.
my hardware sits on wireless network, creating messages, and pushes them to a tunneling router than in it's time push the messages to a middleware PC
with a socket server program, listening for the data.
So your "socket server" runs on the middleware PC and listens on a specific port which the router connects with and sends data.
gizmokaka wrote: when I say the connection breaks I mean, I disconnect the tunneling router from the network,
and reconnect it.
when it's reconnected it's no longer able to receive messages.
It can't receive messages from the RF devices? Or from your "socket server". Any connections that you had from your socket server to the router are dead when you disconnect the router from the network. After you reconnect the router, it must establish a new socket connection to your socket server. Are you saying it doesn't do that?
How does it initially connect to your socket server? The router must be configurable yes? Perhaps you missed a configuration property that tells it to re-connect after it detects the network presence. Or perhaps it is not capable of doing that, if not there is not much you can do.
|
|
|
|
|
I have built a windows form using C#( .NET 2.0 ). The form has a label with text set to “:My label text.” When I build and run the form here everything looks fine.
When a person is running the form in UK he sees the label text as “.My label text:”
I am not able to figure out the reason for the colon to be moved to the end and the fullstop to be moved to the front.
I don’t think the UK locale would be causing this.
Have seen this happening?
Thanks,
Sudhir
|
|
|
|
|
Isn't by any chance the colon and fullstop entered with right-to-left text mode?
|
|
|
|
|
Not only that you should also think about internationalization. In the UK the date and time format is different and they are also using a different codepage (English/US vs English/UK).
|
|
|
|
|
hello techs,
I have a small project which enables database backups.
I have to to do backup's for multiple database @ a time.
For that i need to use Threading concepts.
the below code is for database backup :
-----------------------------------------------------------------------------------------------------
public void backUpDatabase(string DBname, string setBakUpPath)
{
SqlCommand sCom = new SqlCommand("BACKUP DATABASE " + DBname + " TO DISK = '" + setBakUpPath + "' WITH NOFORMAT, NOINIT, NAME = 'Full Database1 Backup', SKIP, NOREWIND, NOUNLOAD,STATS = 10", sCon);
sCom.CommandType = CommandType.Text;
try
{
sCom.ExecuteNonQuery();
MessageBox.Show("Database " + DBname + " : BackUp Done!", DBname + " BackUp", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString(), "Backup ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
sCom.Dispose();
}
-----------------------------------------------------------------------------------------------------
all the databases will be loaded to a list box and i will select a database and clicks on button "Backup Database" and it will starts backup.... I need to do the backup in a thread. Now on the datagrid ... it will show the "db name", "Status : backup going on/backup done" and finally % of percentage of backup in the third colum of grid (u can avoid if this a bit time consuming... )
Please help me to solve it, if any clarifications needed... please ask ... thanks ...
A123-B321
|
|
|
|
|
jikubhai wrote: and finally % of percentage of backup in the third colum of grid
That's a good one considering you are making a blocking call to perform the backup
jikubhai wrote: sCom.ExecuteNonQuery();
|
|
|
|
|
|
What you don't know what "blocking call" means? You might need to study some fundamentals before you develop production applications.... just a thought.
|
|
|
|
|
Hello,
Hope someone can help with this, I've built a collection which I'm then using to populate a ListView. I need to somehow be able to sort the ListView by 2 columns, column indexes 3 then 2. The ListView contains information about advertisements in a publication and I need to be able to sort by section (column 4, idx 3) then page no (column 3, idx 2). The thing is, how?
I know I need to use the ListViewItemSorter method somehow but I've no idea how to attach the required columns. It will only ever be these 2 columns and they will always have the same position in the ListView (idxs 3 & 2).
Hope someone has a work around for this, I've managed to do it in a DataTable but can not get it working here yet. If anyone has a different solution to this problem, please don't be shy. I'm more than open to new ideas.
Thanks in advance everyone,
Scott
|
|
|
|
|
|
Hi,
same as for any other collection you want to sort (array, ArrayList, ...):
write a class that implements IComparer and pass that to the Sort() method; on a LV that
happens through setting ListViewItemSorter property.
Implementing IComparer means providing a single method that takes two objects and returns an int:
int Compare (
Object x,
Object y
)
the int value should be negative, zero or positive depending on the sort order of the
two objects;
you would have to cast these objects to whatever type it is you have in the ListView.Items collection
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi!
I think one important point that might not be entirely obvious is that you sort by one column first and only have to return the result of the second column's comparison if the items to compare are the same in the first column!
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
I need to safely open a text file and send its contents to a textbox, if it doesnt exist i need to create it and then open it and show nothing in the textbox. I keep getting a "file is in use by another process" error.. here's my code..
TextReader fstream;
fp = filepath;
try
{
fstream = new StreamReader(fp);
}
catch (System.IO.FileNotFoundException)
{
File.CreateText(fp);
fstream = new StreamReader(fp);
}
bool done = false;
while(!done)
{
Alert = fstream.ReadLine();
if(Alert = null)
{
done = true;
else
{
textBox1.AppendText(Alert + "\r\n");
}
}
fstream.Close();
|
|
|
|
|
Dio22 wrote: I keep getting a "file is in use by another process" error
If another process has the file open in non "share" mode you will not be able to open it. Perhaps you have it open in some editor or something?
|
|
|
|
|
nope, nothing has it. error only happens when the file doesnt already exist. *shrug*
|
|
|
|
|
Dio22 wrote: error only happens when the file doesnt already exist. *shrug*
Yes that is because you are trying to create it in the catch() while you still have the active StreamReader in the try{} block.
|
|
|
|