|
It's fantastic! Thank you.
But I'm not too fond to use such kind of heavy operations like converting to strings and bachwards.
It is much better than to be asset, but is far from natural.
Thank you, anyway!
HilSoft
|
|
|
|
|
I am new in C# and nobody could clarify this:
Yesterday I created some kind of an observer pattern
I created a delegate and two combo boxes, in one I set an event for changes using the delegate and in the other one I "listen" to that event. This works great, whenever the cahnge occurs in the first combo, the second one adjusts itself accordingly. The problem is if I didn't set a listener yet I get a null object exception for the line where I fire the event. Is this normal or am I doing something wrong ? To solve the problem I verify first if the object is null but I want to be sure I am not doing something stupid
Here is the code (useless lines removed)
public class CountryCombo : ComboBox
{
public event CountryChangedHandler countryChanged;
...code
public CountryCombo() : base()
{
...code
this.Leave += new EventHandler(CountryCombo_Leave);
this.BindingContextChanged += new EventHandler(CountryCombo_BindingContextChanged);
}
void CountryCombo_BindingContextChanged(object sender, EventArgs e)
{
this.countryChanged(SelectedValue.ToString()); //********* This where the error occurs if no listener
//********* this.countryChanged is null
}
void CountryCombo_Leave(object sender, EventArgs e)
{
if (this.SelectedIndex == -1 | this.SelectedIndex == 3)
{
this.SelectedIndex = 0;
}
this.countryChanged(SelectedValue.ToString());
}
}
public delegate void CountryChangedHandler (string countryISO3);
public class ProvinceCombo : ComboBox
{
...code
public ProvinceCombo(CountryCombo combo) : base()
{
combo.countryChanged += new CountryChangedHandler(ChangeCountry);
...code
}
public void ChangeCountry(string iso3)
{
...code
}
}
|
|
|
|
|
~~~Johnny~~~ wrote: To solve the problem I verify first if the object is null but I want to be sure I am not doing something stupid
Nope, it's not stupid. It's what you're supposed to do. Check if countryChanged is null before firing an event on it.
Logifusion[^]
|
|
|
|
|
Can you summerize the logic behind that?
|
|
|
|
|
You declare this:
public event CountryChangedHandler countryChanged;
countryChanged becomes a field in your class. But what does it store? Behind the scenes, countryChanged is actually a reference to a linked list of delegates that subscribed to the event. Initially, the field references null because there are no subscribers. The delegate CountryChangedHandler is actually an item in a linked list, meaning that within it is a pointer to the next item. So, when you subscribe to the event, a new CountryChangedHandler is created and added to end of the linked list. The reason Microsoft decided to do this was because it's a very efficient way to manage all the subscribers to a particular event. What it means for us is that you have to check if the event field is null before firing.
Logifusion[^]
|
|
|
|
|
Well, that couldn't be clearer, it gives me a good understandidng of what is actually happeneing.
Thanks a lot for your help
|
|
|
|
|
Hi
What is the activex control name for PivotTable and SpreadSheet?
I want to use them in a Windows Form Application
is it Microsoft Office Web component?
-- modified at 12:54 Thursday 27th July, 2006
|
|
|
|
|
Is it possible to overload a function from VS2005 IDE?
If so, I want to overload graphics.drawline() which signature in CF is drawline(pen, int x1, int y1, int x2, int y2). I want to change it to drawline (pen, point A, point B).
Any help?
Donkaiser
|
|
|
|
|
er, that overload already exists!
(in class System.Drawing.Graphics)
public void DrawLine ( System.Drawing.Pen pen , System.Drawing.Point pt1 , System.Drawing.Point pt2 )
|
|
|
|
|
Sorry! it's for CF. this overload is missing. But my point is to see if it's possible to overload IDE methods.
|
|
|
|
|
Whats an IDE method?
Either 2.0 or 3.0 ( idk which ) has a method for adding additional methods to a class. If you do a web search for new features of the two it can direct you. If those are not available the pattern is a wrapper class.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Im using .net 2.0. googling around still haven't found anything yet.
Donkaiser
|
|
|
|
|
Its extension methods and I think it is in 3 only. Looks like you need a wrapper class.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Yeah, I don't think it's possible to overload a native method. and the only solution is to do a wrapper.
Donkaiser
|
|
|
|
|
Hi,
I was hoping if someone could help me with this problem. I want to edit
datagrid entries without using a linkbutton column for edit and update.
maybe we could do this using javascript. But I dont know how?
On an 'edit settings' button click outside the datagrid, the cells in the datagrid should change into dropdownlists and textboxes with earlier values maintained.
Thanks!
Monisha
-- modified at 10:50 Thursday 27th July, 2006
|
|
|
|
|
In VS 2005 you can do edits in-place within the grid. You only need to have an 'Edit' trigger if you want to open up a seperate view of the record.
|
|
|
|
|
I am using the Socket class to communicate between two applications and if I close my server app closing the socket connections my client app is unable to detect that it is closed. Even doing a send from the client app does not throw an exception. Does anyone know how to detect if a socket has been closed from the other side?
Thanks
Kurt
|
|
|
|
|
What does the Connected property read as when you do this? Is there a timeout issue, i.e. you haven't waited long enough for the timeout to kick in and say the connection has been closed?
only two letters away from being an asset
|
|
|
|
|
Connected property is true. Even tried waiting a few minutes. Using asynchronous methods which do not use a timeout I believe.
|
|
|
|
|
i want to catch any key down event in my windows form.
but it doesn't run, because there is maybe an other control in the formular that is focused, so the key down event reacts only on that inner control.
how can i catch any keydown event without referencing each control in the formular to the keydown event?
another method i know is to create a menustrip and give them shortcuts (but i think it's not the perfect solution)
_______________________
where is the "any" key?
-- modified at 7:11 Wednesday 9th August, 2006
|
|
|
|
|
Do you want catch just any key down
or only key down when one of the child controls of your form (or the form itself) is focused?
|
|
|
|
|
any key down
not specially to a control in the form
|
|
|
|
|
You have to install windows hook procedure to intercept all keyboard events.
Look at “How can I use 'Hooks' in .NET” article at following link
http://72.14.203.104/search?q=cache:NUhXDPTnLJgJ:www.syncfusion.com/FAQ/WindowsForms/FAQ_c70c.aspx+%22DllImport%22+SetWindowsHookEx+WH_KEYBOARD+C%23&hl=en&gl=ca&ct=clnk&cd=1
|
|
|
|
|
You can read about windows hooks in .Net here <a href="http://msdn.microsoft.com/msdnmag/issues/02/10/CuttingEdge/">http://msdn.microsoft.com/msdnmag/issues/02/10/CuttingEdge/</a>[<a href="http://msdn.microsoft.com/msdnmag/issues/02/10/CuttingEdge/" target="_blank" title="New Window">^</a>]
Use WH_KEYBOARD when installing the hook procedure with SetWindowsHookEx
Use following code to detect key down in your hook
static readonly int WM_KEYDOWN = 256,
public Int32 KeyboardProc(int code, Int32 wParam, Int32 lParam)
{
if ((Int32)wParam == (Int32)WM_KEYDOWN )
{
// do processing
}
// do not forget to call next hook !!!!!!!!!!!!
// CallNextHookEx is win32 api that can be loaded to .Net
// using dll import like they did with setwindowshookex in example
return CallNextHookEx(hHook, code, wParam, lParam);
}
|
|
|
|
|
Try setting the form's keypreview to true, then catch the key down of the form.
|
|
|
|