|
I have some LinkLabel controls in a Windows Form. When the user clicks a LinkLabel the application displays a form containing data pertaining to the object selected, determined by the LinkLabel's text. The form is not displayed as a dialog and it is not maximized by default. The behavior I would like to achieve is once the user clicks out of the popup form (for example, he/she clicks another area in the application's main form) the popup form should disappear.
I have tried subscribing to the form's LostFocus event and creating the event handler for it. However, when I click away from the form, it simply goes behind the application form. Is LostFocus not the appropriate event? Or should I handle this in the popup form rather than from the "caller" form?
|
|
|
|
|
Have you tried putting form.Close() in the popup form's Deactivate() event?
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
No, I have not. I will do that though. Thanks.
|
|
|
|
|
Hi,
I'm trying to populate a listview control and my query is LINQ. I used one of the table (Production.Product) of AdventureWorks database.
At first i have problem populating the header, but i figured it out after an hour. The code below is the code on how to populate column in listview using LINQ.
Code:
----------------------------------------------------------------------------------------------
ProductID Name ProductNumber MakeFlag FinishedGoodsFlag Color
----------------------------------------------------------------------------------------------
317 LL Crankarm CA-5965 0 1 Black
318 ML Crankarm CA-5938 0 1 Black
319 HL Crankarm CA-5990 0 1 Black
320 Chainring CA-5932 0 1 Black
---------------------------------------------------------------------------------------------
DataClasses1DataContext db = new DataClasses1DataContext();
DataTable dt = new DataTable();
DataColumn dc = new DataColumn();
DataRow dr;
var products = from p in db.Products
where p.Color != null
select p;
#region getHeader
var headers = products.First();
foreach (var columnHeader in headers.GetType().GetProperties())
{
lvw.Columns.Add(columnHeader.Name);
}
#endregion
Now, my problem is how do i populate the result of my query and add it to listview. Actually, i can populate it like this,
ListViewItem lstItem = null;
foreach (var itms in products)
{
lstItem = new ListViewItem(itms.ProductID.ToString());
lstItem.SubItems.Add(itms.Name);
lstItem.SubItems.Add(itms.ProductNumber);
..... and so on
}
The problem on the above code is that, what if i have a 25 columns in my query result? I have to type in my code 25x the lstItem.SubItems.Add(value) which kinda hassle for me. I want my function in populating the listview to be dynamic.
Anyone out there can help me to solve my "simple (i think)" problem.
Thanks and regards
Jessie
if(you type your code here) {
Messagebox.Show("You help me a lot!");
}
else {
You help me = null;
}
|
|
|
|
|
ListView is quite limiting control. You can take a look on this extended ListView control A Much Easier to Use ListView[^] that supports data binding.
Hope it helps.
M.
|
|
|
|
|
Wow - that article has 453 5 votes, yet only 56 downloads.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
As soon as I saw you response I knew the article, it is an excellent article but a hugely complex control. I played with it but found it too complex for my requirements. Mind you I also trashed Infragistics for the same reason!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have no idea how the hamsters track the downloads but I guess that the low
number of downloads might be caused by the fact that the download is just a link to a sourceforge.net download?
All the best,
Dan
|
|
|
|
|
With the Browse Code tab it isn't really necessary to download the code to learn what it does and how it does it. That may explain the low numbers.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
thanks for the link. maybe ill try it later.
cheers!
if(you type your code here) {
Messagebox.Show("You help me a lot!");
}
else {
You help me = null;
}
|
|
|
|
|
Hello Everyone,
I'm trying to automate file's downloading process from my server using winscp command line stfp downloader. It was required to process some standard output to detect errors and some events, so I redirected the standard output and standard input of process and set the shellexcute to false. Now I'm able to see the output messages on rich text box using asycn readline (BeginOutputhttp://msdn.microsoft.com/en-us/library/system.diagnostics.process.beginoutputreadline.aspx[^]) method provided in Process library. Now my problem, how can I write my program such that it is able to write commands to standard input asycn and at same time making sure that no command is missed, if previous command is under processing.
Let say I've a text box and button..if I press a button then it writes the command on text box to standard input of the process and then it waits for the reply..and lets assume this whole task takes 2 seconds..but during this 2 seconds user can enter more commands which can not be ignored so must be added to some queue, which can executed later on. I'm not sure how should I achieve this? I'm sorry if I'm misunderstanding anything here..but I've no experience with mutli threading in C#..Please suggest some design pattern to do this..any help would be appreciated..
Thanks,
Regards
Shivam Kalra
modified on Friday, June 24, 2011 10:44 PM
|
|
|
|
|
You need to use a FIFO queue, lots of possible samples here[^].
The best things in life are not things.
|
|
|
|
|
Hello Experts,
I am Showing a form from another form. and it Set focus on Child Form by default.
But I don't want to lost focus from parent form.
So pls suggest me how can i do that?
For Ex: ChildForm Pf = new ChildForm;
Pf.Show();
Code set focus on PF Form but i do't want to change the previous focus.
Thanks
If you can think then I Can.
|
|
|
|
|
Try to do reset the focus on the caller form.
Form a = new Form();
a.Show();
this.Focus();
Bye
|
|
|
|
|
From MSDN[^]:
Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.
So, you should probably use Activate in this case.
|
|
|
|
|
That's a good point, I should be more detailed, but I was in hurry and he specifically spoke about the Focus.
Thanks
|
|
|
|
|
I transitioned from VB6 where SetFocus was the only thing you had (and an annoying thing too, kept throwing exceptions when it failed, rather than returning true or false).
I eventually discovered about the Select method while reading MSDN documentation about focus change events. Anyway, I'm guessing Select/Activate is more robust than SetFocus.
|
|
|
|
|
i'm using a msmq for my application and i create a queue when the application is loading.And to receive the message i set the timespan for 10, in the debug mode it works fine and the messages received as expected, but when i deploy the application in the release mode it gives a "timeout exception" at the receive method.
i would really appreciate your ideas about this .
thanks in advance.
|
|
|
|
|
If there are no messages in queue then it will raise tiemout exception.
No need to worry about that exception .. just catch it and say there are no messages in 'Q'.
No Defeat Is Final Until You Stop Trying!.......
|
|
|
|
|
You should also possibly increase your timeout (or at least make it configurable)
Or start another thread/method etc. to listen for the next message.
|
|
|
|
|
Hi,
I don't know much about icons and bitmaps so please bear with me.
I have a .ico file and several .png files provided to me. The code I have overlays the .png file to indicate a status. The code seems to work fine right up to the point that it gets an icon. The icon doesn't quite look right though it's hard to see in the system tray.
So I changed the code to write it out to a file and now it seems to look even worse (looks like a very small colour pallette) so I don't know if it's the same issue.
Here's a photo of the two files opened up on Visual Studio -
http://flickr.com/gp/psmithson/9s2KnQ
This is an extract of the code producing the two files -
Bitmap bmp = new Bitmap(stream);
bmp.Save("c:\\tmp\\stage1.ico");
IntPtr Hicon = bmp.GetHicon();
Icon icon = Icon.FromHandle(Hicon);
using (var fs = new FileStream("c:\\tmp\\stage2.ico", FileMode.Create, FileAccess.Write, FileShare.Delete))
{
int pgs = icon.Height;
icon.Save(fs);
}
The system tray icons don't look that bad but they're not quite right. Is there a limited pallette available in the system tray?
Thanks.
Peter.
|
|
|
|
|
This may be of help:
clickety[^]
Guy
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
Standard .ico icons do not support multi-level transparency. If your PNG overlay or generated bitmap contains that, strange things will happen. Saving to a .ico may well use a low colour depth by default.
I suspect the problem lies with where you are setting the system tray icon. That is a p/invoke if I remember right? Can you post the section where you set that (including setting up the image object that you assign to it)?
|
|
|
|
|
Transparency could be the main problem. The colours don't look so bad in the actual system tray but there is a black blob at the top right where it should be transparent.
I just dragged a NotifyIcon onto the form from the Toolbox under "Common Controls".
I get this generated -
this.notifyIcon = new System.Windows.Forms.NotifyIcon(this.components);
Then I just set the icon very simply -
notifyIcon.Icon = iconNoStatus;
The "iconNoStatus" is just an Icon that has been created using the code I posted initially.
Thanks.
|
|
|
|
|
Oh, I didn't know about that class. I guess that hides all the tricky bits.
I don't see anything in the Icon class that allows you to set colour depth – perhaps I am missing something?
|
|
|
|