|
Hi,
I've changed my form to use a context menu for basic CRUD operations after using a menu previously.
Now, if you fill out the form (Winform C# 2.0) and right click "save", the last field on the databound form doesn't update the property value in the business object. If I tab through it then the value's updated properly.
So it seems that if the cursor is still focused in that last textbox as I invoke the save, the databinding doesn't update the property and I end up with a blank value in the database.
How can I ensure that the property gets updated if the user doesn't tab out of it?
Seems simple enough but I've gotten myself so confused that I can't think straight, so I ask for help! Thanks.
|
|
|
|
|
Took me quite some time to figure that one out, too.
The update back from control back to BO is after on leave of the control. I notice that if the user move from the control to say a tab page or button, it may not get fired.
Change the update mode to on property changed instead of on leave, ie
this.txtUserCode.DataBindings.Add("Text", UpdateObject, "UserCode", false, DataSourceUpdateMode.OnPropertyChanged, string.Empty);
The BO will get updated on every changes on the control, though.
|
|
|
|
|
Thanks for the response. Your suggestion worked great!! It had me stumped for a while.
|
|
|
|
|
My book on LINQ hasn't arrived yet, so this might be a stupid question or really basic, but anyway...
Is it possible to build a dynamic where clause?
"On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't.
"I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it."
-Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.
|
|
|
|
|
|
That's some mighty fine Google work. I'm annoyed, however, that it didn't come up in my googling.
"On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't.
"I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it."
-Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.
|
|
|
|
|
Yes, I was fiddling abit with dynamic query also.
|
|
|
|
|
Clicking the code link below posted my original reply, and I can't edit it.
Anyway, MatchTypes is an enum where I make use of string's StartWith, EndWith, Contains or Equals functions to filter the search string.
cmbFields contains string fields from the object.
txtValue is the value entered.
I am not able to search using wildcard though ie "ABC*"
IQueryable q = stockPositionDB.StockPositions;
if (this.txtValue.Text.Length > 0 && this.cmbFields.Text.Length > 0)
{
string s = string.Empty;
string match = ((MatchTypes)cmbMatchType.SelectedIndex).ToString();
ParameterExpression param = Expression.Parameter(typeof(StockPosition), "c");
ConstantExpression constant = Expression.Constant(this.txtValue.Text);
MemberExpression prop = Expression.Property(param, typeof(StockPosition).GetProperty(cmbFields.Text));
System.Reflection.MethodInfo mi = s.GetType().GetMethod(match, new Type[] { typeof(string) });
MethodCallExpression call = Expression.Call(prop, mi, new Expression[] { constant });
//BinaryExpression filter = Expression.Equal(prop, constant);
LambdaExpression pred = Expression.Lambda(call, param);
MethodCallExpression expr = Expression.Call(typeof(Queryable), "Where", new Type[] { typeof(StockPosition) }, Expression.Constant(q), pred);
q = q.AsQueryable().Provider.CreateQuery<stockposition>(expr);
this.bindingSource1.DataSource = q;
}
|
|
|
|
|
I am attempting to resolve a domain name to it's ip address, but am having a problem. When I call 'Dns.GetHostEntry("www.giftwich.com");', then try to connect to this ip, I get internet error 400, "The Page Cannot be Found". I think it is because the site is not the only one on a particular computer, or perhaps I am getting the ip address of the DNS server for that host. I don't know, but can anyone shed some light on how to get around this so I can connect to a site like this through the ip address? Thanks,
-Jeff
|
|
|
|
|
If you can ping the returned address, then the server is a Virtual Server in that it's mappings are based on name (multiple domains on one ip address).
Try it the other way around and feed the ip address in and see if you get the dns name (giftwich.com).
|
|
|
|
|
I don't get the dns name... it is something different. Since it is a virtual server, does that mean I cannot connect to it directly using the ip address?
-Jeff
|
|
|
|
|
Yeah with a virtual server, the IP address will only get you to the server itself. From there, it's routed based on the header info for the file area for the site. It's doable but complicated. Not sure exactly what you're trying to do but maybe set up two methods. One connects via the dns name, the other by IP address. If IP address returns a 404, then connect by dns name instead.
|
|
|
|
|
Ok, thanks for the help!
-Jeff
|
|
|
|
|
Can anyone tell me why strSpd2 in the example below ends up being a
blank string when formatting a zero value? It would seem to me that
strSpd2 should end up being "0.0"
double val1 = 14.38009
double val2 = 0.0;
string strSpd1 = "";
string strSpd2 = "";
// This formats correctly. strSpd1 = "14.4"
strSpd1 = String.Format("{0:##.#}", val1);
// This does not format. strSpd2 = "" Why is this blank and not "0.0"
strSpd2 = String.Format("{0:#.#}", val2);
Craig
|
|
|
|
|
Yes, the # means "Put a digit here if it is significant". Since leading and trailing 0's are not significant, you are getting no value. Use, "{0: 0.0}" as your format specifier, as described here[^].
-Jeff
|
|
|
|
|
have a menu strip in my application with:
File Edit View Tool
Under my view heading I have a option to see end of line characters, what I want do is have it so the user knows when this has been clicked on, the problem is that I have an image in the TooStripMenuItem so you can't see the check mark when it is clicked. Any ideas?
|
|
|
|
|
Perhaps you could change...
1. The style of the menu item (ie, bold means active, normal means inactive)
2. The image associated with the menu item
3. The text for the menu item (Like "Show Newlines" vs. "Hide Newlines")
Hope this helps,
-Jeff
|
|
|
|
|
Hi all,
Here is my question. I have 3 forms,
FormMain
Form1
Form2
Form1 and Form2 are loaded into panels on FormMain. I need to access Form2 from Form1. Say I need to disable Form2 if a button is clicked on Form1 BUT I need to do it from Form1 (it is easy to control the instances from FormMain but that is not what I need).
Any suggestion?
Thanks!
-Kam
|
|
|
|
|
Naz wrote: I need to access Form2 from Form1. Say I need to disable Form2 if a button is clicked on Form1 BUT I need to do it from Form1
Pass form2 to the constructor of form 1 on load.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Ok, let me explain it again. Neither Form1 nor Form2 are aware of existence of one another. They are loaded in MainFrom. If I pass Form2 to the constructor, I suppose I need to create a new instance of the form. Then the instance in MainForm would be independent to this new instance and Form1.
Maybe I am not following you. Please explain more if you get a chance.
-K
|
|
|
|
|
If I understand you correctly, MainForm knows of the instances of Form1 and Form2. Have Form1 raise an event in MainForm that disables (or whatever other action) it's instance of Form2.
|
|
|
|
|
I see. Could you be able to write a few lines of code on how doing this? I am thinking of using delegates. I have already spent so much time on this and finally someone has an answer! Thanks a lot!
|
|
|
|
|
You're on the right track. Declare an event in Form1, a delegate and handler method in MainForm and you should be good.
|
|
|
|
|
A better bet for you would be to use a moderator class. The main form would create the mediator and the mediator would be responsible for managing your forms. As an example:
In FormMain:
private Mediator _mediator = new Mediator();
_mediator.CreateForm1();
_mediator.CreateForm2(); In the mediator class, the CreateFormn methods would be responsible for instantiating the forms. Obviously, the mediator would catch events from the forms and respond to them to manage the state as appropriate.
|
|
|
|
|
Pete O'Hanlon wrote: A better bet for you would be to use a moderator class. The main form would create the mediator and the mediator would be responsible for managing your forms. As an example:
In FormMain:
private Mediator _mediator = new Mediator();// Create an instance of Form1_mediator.CreateForm1();_mediator.CreateForm2();
In the mediator class, the CreateFormn methods would be responsible for instantiating the forms. Obviously, the mediator would catch events from the forms and respond to them to manage the state as appropriate.
I didn't even know that could be done. That would be the way to go. It seems to me like at least once every week I learn something from you Pete. Got my 5.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|