|
abcurl wrote: Can you please provide some piece of code associated with SetMonitorContrast
function
Is Google broken there? I told you the exact API to search for - how hard can the rest be?
|
|
|
|
|
I have the following code in one project file. It works just fine and has for a long time:
if (qrySearchResults.Rows.Count > 0)
{
this.Hide();
SearchResults sr = new SearchResults();
sr.ShowDialog();
this.Show();
}
Then I added this to a new project (and solution) I'm doing and get an error message:
if (queryResults.Rows.Count > 0)
{
this.Hide();
SearchResults resultsWindow = new SearchResults();
resultsWindow.ShowDialog();
this.Show();
}
I'm essentially doing the same thing yet get an error on the new one saying that it can't access something that has already been disposed of. So I added:
if (!this.IsDisposed)
{
this.Show();
}
and now it works. Why would the first project work fine without this additional code but the second one has to have it?
[EDIT] I should say that the 'resultsWindow' has two buttons. Either Search Again or Close. If they Close, I close this search criteria window in the results Window and if they choose search again, then I want this to show again so I just close the results window.[/EDIT]
I'm using VS2008 in a Winforms project. It is possible the first project was created with VS2005 but not sure. I didn't do it. I promise!
I have nothing more to say.
|
|
|
|
|
Long variable names break your code!
Seriously though, you should use the return value of ShowDialog to decide whether to re-show the form. (Set the result by putting DialogResult properties on the buttons.) Closing it from within resultsWindow will result in the behaviour that you describe because that will happen before ShowDialog returns, so when you call Show, resultWindow has already killed the form. Pulling the rug out from underneath an executing form like that is rude.
|
|
|
|
|
This is the code I used in the resultsWindow:
private void cmdClose_Click(object sender, EventArgs e)
{
SearchCriteria sc = (SearchCriteria)Application.OpenForms["SearchCriteria"];
sc.Close();
SearchCriteria.impDS.Dispose();
this.Close();
}
This is the code from the previous project:
SearchInput si = (SearchInput)Application.OpenForms["SearchInput"];
si.Close();
SearchInput.ds1.Dispose();
this.Close();
So you can see I do the exact same thing and the other code works fine without checking. I agree that there are better ways. Thanks for pointing out checking what ShowDialog returns. I'll look into doing that.
BobJanova wrote: Pulling the rug out from underneath an executing form like that is rude
I didn't mean to be rude.
I have nothing more to say.
|
|
|
|
|
twohowlingdogs wrote: So you can see I do the exact same thing and the other code works fine without checking.
If the behaviour is different, then there "must" be a difference. The check on "this" implies that "this" might be disposed, before the dialog is closed. Are you calling an explicit dispose on that particular form somewhere?
I are Troll
|
|
|
|
|
Eddy Vluggen wrote: If the behaviour is different, then there "must" be a difference.
I will not argue with that! I just can't find it!
I don't think I'm calling a Dispose anywhere else. I'll look into that! What I said I'm doing in the first post is working and working correctly. So I'm not worried, but considering how I am, I would like to find out why!
I have nothing more to say.
|
|
|
|
|
when closing a Form, its survival depends on whether it was shown by calling Show() or ShowDialog(). Maybe that explains the difference you're seeing.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
hi
i have in my C# program form with DataGridView
when i pick row and press button, I present control panel with some textboxs
that fill from the DataGridView.
when the control panel is show - i see his build on the screen (And it's not pleasing to the eye).
how to show this control panel Instantly ?
thanks in advance
|
|
|
|
|
Gali1978 wrote: how to show this control panel Instantly ?
by writing efficient code, not having blocking calls in GUI event handlers, and keeping form complexity reasonable.
you'll have to provide a lot more information to get effective detailed help.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I think use Control.SuspendLayout() and Control.ResumeLayout() to surround your "fill" code will help.
|
|
|
|
|
|
You beat me to it, great answer.
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!"
— Hunter S. Thompson
|
|
|
|
|
One other thing to try is to have readily instantiated controls at hand positioning them dynamically as needed filling them with data and the making them visible.
Just a thought.
Cheers!
|
|
|
|
|
You can try using virtual mode:
http://msdn.microsoft.com/en-us/library/ms171622.aspx[^]
At my previous company it was a requirement for DataGridView's due to performance reasons.
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!"
— Hunter S. Thompson
|
|
|
|
|
Is there any better way in c# to check items in a collection contains common property
besides looping through with a flag and finding out?
say for example, a text item collection contains fontweight bold for all text item
- Regards - J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
|
|
|
|
|
Not really. You may be able to do it with Linq, but how to do that will depend on the items you are talking about.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
|
Add a break :
textBold.Checked = true;
foreach (Item item in Items)
{
if (item.FontWeight == FontWeights.Normal)
{
textBold.Checked = false;
break;
}
} As I said, you could do it with Linq:
int normal = Items.Count(item => item.FontWeight == FontWeights.Normal);
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
thanks a lot.
implemented by storing the item properties in a list
and list.contains(FontWeights.Normal). it worked.
- Regards - J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
|
|
|
|
|
Now the solution doesn't make much sense because you've removed a link in the chain. Other people might have found this useful, but you've made it hard for them.
Never, ever, remove a message that's been replied to.
|
|
|
|
|
I agree, however IMO you're asking the wrong person. It is Chris who simply shouldn't present a "Delete" widget for messages that have replies. I have asked him many times, he eventually fixed half of it (the top level message).
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I know. I was going to post a request and then thought, what's the point - it's been asked for before and still isn't here.
|
|
|
|
|
I've asked for it on Q&A as well a few times - it really annoys me when you answer a question and it gets deleted because they (presumably) don't want the answer to help anyone else...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
I remember some sites where it was expected to remove a problem once it got solved.
CP however doesn't expect that; it does offer a "Delete" widget, and when used, you're bound to get "don't do that" comments. Pretty confusing if you ask me.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Yes, and I have no problem with it's existence. If you post a stupid question, and that makes you realise just how dumb you have been, then deleting it before anyone notices or answers is fine by me.
But, when it is a complicated answer that can take half an hour to get right, and the OP deletes it as soon as he reads it, that does annoy me, I admit.
If nothing else, it doesn't appear in any list I can access to copy it or refer anyone else to next time...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|