|
He figured it out and fixed it. Obviously not a Hlp Urgnt Pls at all, just a beginner. Just like you and I were
Jon
Smith & Wesson: The original point and click interface
|
|
|
|
|
Oh I wasn't laughing at him in particular. 
|
|
|
|
|
Hi,
You can use the below also.
if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
return;
Regards,
Charith
Charith Jayasundara
|
|
|
|
|
Hi,
IMO the best way is by testing for a positive, as in:
if (openFileDialog1.ShowDialog() == DialogResult.OK) {
} }
That way, if for whatever reason something other than OK and Cancel gets returned,
nothing will happen.
I tend to avoid negative tests, they tend to confuse people sometimes.
|
|
|
|
|
Hi Luc. I used to have it that way but then for some reason the openfiledialog would show again if you selected the file and clicked on OK. When I changed it to a negative test then it worked fine.
Thanks for taking the time to help and reply. It is greatly appreciated. Someday I will be able to help the guys out as well and be a great programmer like most of the guys here.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Hi,
Kwagga wrote: for some reason the openfiledialog would show again
Seeing the dialog more than once cannot depend on how you formulate the condition;
it would need either a loop (for, while, ...) or the method being called more than once.
|
|
|
|
|
This is code from another project I am working on. This is where the openfiledialoge is opened twice instean of once.
private void btnOpenFix_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtboxFixed.Text = openFileDialog1.FileName;
}
if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
this.Close();
Now that I know how to resolve this in one code statement I can fix it.
So, I would rather have it like this:
private void btnOpenFix_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() != DialogResult.OK)
{
return;
}
else
txtboxFixed.Text = openFileDialog1.FileName;
}
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Ah, see? You're calling ShowDialog twice.
You could store the result in a local variable:
DialogResult res = openFileDialog1.ShowDialog() ;
if ( res == DialogResult.OK ) ... ;
if ( res == DialogResult.Cancel ) ... ;
or use a switch:
switch ( openFileDialog1.ShowDialog() )
{
case DialogResult.OK : ... ; break ;
case DialogResult.Cancel : ... ; break ;
}
|
|
|
|
|
Hi,
adding to what PIEBALD told you, I find it rather strange that your program would
do something when CANCEL is clicked; normally cancel means "don't do anything, since I have
changed my mind". This also means you should NOT close the form itself.
I trust the above is part of the Microsoft recommendations for a Graphical User Interface.
|
|
|
|
|
Hi all,
I used this code for computing total price<b></b> of all item that customer ordered them:
public Double total <br />
{<br />
get<br />
{<br />
double t;<br />
if (items == null)<br />
{<br />
return 0;<br />
}<br />
foreach (cartitem Item in items)<br />
{<br />
t += Item.Totalline;<br />
}<br />
return t;<br />
}<br />
} but this error occured when i run above code:
Use unassigned local variable 't'
Now where i should define 't'?
Hoda
|
|
|
|
|
Hoda,
The line
<br />
double t; <br />
should be changed to:
<br />
double t = 0;<br />
You need a default value. The first iteration of your foreach statement is trying to add a double value to null which doesn't work. So give 'er a default value and be off
Hogan
|
|
|
|
|
Dear Hogan,
thank you very much for you response.
Hoda
|
|
|
|
|
I am developing an application where multiple users will have concurrent access to a database for reads, writes/adds, deletes and updates. Much of the user interface will be through the DataGridView control. I am trying to come up with as elegant a solution as possible to dynamically update a DataGridView for, say, User #2 if User #1 makes a database change to the same table that User #2 is viewing. It seems that I have to programatically refresh the grid no matter how I have it bound to the database (connected or disconnected recordsets). Am I missing something? Is there something in ADO.Net that will enable me to bind data to a grid such that any changes to the database will almost immediately be reflected in the grid with no forced/programmatic refresh?
Thank you...
|
|
|
|
|
No There is no such facility. The closest thing to what you want is SQL Server Notifications, but that is cumbersome and overkill here.
Your idea to update user1 of changes by user2 may not be as good a design as you think. Some questions to consider:
1. How likely is it that multiple users will be modifying the same data?
2. What is the likelyhood they will be viewing the same data (same subset of rows in the same table).
3. If user1 edites field A of row 2 just as your update notification arrives for User B having done the same, what will you do - overwrite user1's change? how annoying might that be?
In most cases both 1 and 2 are relatively rare, so all the network round trips needed to even determine if users need to be synchronized is not worth the negative impact on performance and scalability. The normal practice here is to detect collisions only when the user commits changes, and refuse them if the modified data had additional changes after the first user read them, but before he posted changes (typically by adding a timestamp field to each row, and comparing the timestamps - only allow update if they are still equal).
|
|
|
|
|
|
From the help on SqlDependency Class:
" SqlDependency was designed to be used in ASP.NET or middle-tier services where there is a relatively small number of servers having dependencies active against the database. It was not designed for use in client applications, where hundreds or thousands of client computers would have SqlDependency objects set up for a single database server."
Not a good ideal in this context.
|
|
|
|
|
when do we get StackOverFlowException? In what kind of situation cos i am in one.
|
|
|
|
|
Most of the time, you won't face this situation. But when there is a dead loop, StackOverFlowException will be thowed.
|
|
|
|
|
Generally when i run into it it's a case of infinite recursion. If you're running into it then the debugger should tell you where the problem is.
|
|
|
|
|
Most of the time this happens when you recursively call a method infinite times, like in the case of this getter:
public int SomeGetter
{
get { return SomeGetter; }
}
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
the most likely way to get a stack overflow is by having a property that refers
to itself, instead of refering to the data member that probably has a very similar name.
|
|
|
|
|
Hello everyone,
I am wondering why do we need to derive some type from IEnumerator<T>? Could anyone show me some useful samples?
I think using IEnumerator<T> itself should be enough in all cases?
thanks in advance,
George
|
|
|
|
|
Well, when to derive or just use the interface is according your context. If using IEnumerator is enough, you needn't derive from it. But sometimes, your class has its own responsebilities besides IEnumerator. So you will implement this interface.
|
|
|
|
|
Thanks adamzhang,
I can understand this point, such as the derived class may have some special rules for MoveNext.
But my confusion is how to initialize and create an instance of such derived class? Could you show a sample with some pseudo code please?
regards,
George
|
|
|
|
|
I'm sorry, but the term you are looking for is not derive. It's implement. There is a whole world of difference in OO terms.
|
|
|
|