|
Good morning,
I am self-teaching myself and I am trying to find a tutorial, examples, direction on how to update a combobox collection of items in Form 1, after I do an insert into the database from Form 2. I am using Access database because thats what I understand, have available to me and I dont want to try learn multiple software packages at the same time.
I have Visual Studio 2019.
I was creating a bill management program for me and from the creditors menu (Form1), which just lists all the creditors names in a combobox, an exit, a new bill and edit buttons, I select the new bill button and it takes me to creditorEditor (form2) and it is there where I add a new bill. Upon clicking the save button, it adds the information to the original database, closes Form 2 and shows form 1 once more. Upon returning to Form 1, I want to be able to click on the combo box and see the new addition of the creditors name, without having to exit out one menu level then returning.
I am not sure I am asking this correctly, if not please tell me what I should be providing for information.
Richard
Disable Vet
Grandfather
Pain in the @ss
|
|
|
|
|
A key piece of information: what happens when you select one of the creditor names in the ComboBox in Form1 ? Does tha open up Form2 again, and display the creditor information and/or allow editing it ?
Getting the new creditor name back to Form1 is easy:
Form2 f2 = new Form2();
f2.AddCreditorName += UpdateComboBox;
public void UpdateComboBox(string newCreditorName)
{
comboBox1.Items.Add(newCreditorName);
}
public Action<string> AddCreditorName = null;
if (AddCreditorName != null) AddCreditorName(CreditorNamtmeTextBox.Text);
Notes:
1) consider hiding/showing the instance of Form2, rather than creating/closing a new instance of Form2 ... of course that may mean you'll need to write some code in Form2 to clear all the entry fields.
2) the act of injecting executable code (the delegate instance aka 'handler) into an instance of Form2 ensures "separation of concerns:" it prevents dependencies between forms causing unexpected side-effects.
3) imho, it is best practice to validate user entered data in the execution context in which it occurs (instance of Form2, here), and to not allow users to make choices that will lead to errors. An example: disable the 'Save button until validation is complete, but, of course, leave a 'Cancel button enabled.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
Thank you for response.
What I ended up going with is as follow:
What I did was separate out the loading of the creditor information into its own operation. It used to be under the CreditEditor_Load, now I just call the operation there and then I am also able to call that same operation from an event handler.
Not sure this is necessarily the best way, but it seems to work exactly as I want.
What do you think?
Richard
void CreditorDataLoad()
{
try
{
cbo_BillName.Items.Clear();
string query = "select C_Name From Creditor";
AC.cmd.Parameters.Clear();
AC.cmd.CommandType = CommandType.Text;
AC.cmd.CommandText = query;
AC.openConnection();
AC.rd = AC.cmd.ExecuteReader();
if (AC.rd.HasRows)
{
while (AC.rd.Read())
{
cbo_BillName.Items.Add(AC.rd[0].ToString());
}
}
AC.rd.Close();
AC.closeConnection();
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
}
private void btnNewBill_Click(object sender, EventArgs e)
{
billName = null;
this.Hide();
creditEditor f2 = new creditEditor(this);
f2.FormClosed += new FormClosedEventHandler(creditEditor_FormClosed);
f2.ShowDialog();
}
void creditEditor_FormClosed(object sender, EventArgs e)
{
CreditorDataLoad();
}
|
|
|
|
|
If a user "kills" an app, form closed does not get called; in case you were counting on it to "save" your data.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hello everybody,
I have to modify this code (the programmer who did it is not longer with us)
The problem is:
If you type the userid and password and click LOGIN: the program take the userid and password
but if you FORGOT your password, and click: Forgot password(Olvide contrasena), the programa check if you did not type the userid and show you a warning, the problem is that if you type the userid, and click Forgot the password, the userid it is not reads on the program. Any help?
The .chtml
<div class="box box-primary login-box ewLoginBox">
<div class="login-box-body">
<p class="login-box-msg">@Html.Raw(Language.Phrase("Login"))</p>
<div class="form-group">
<div>
<input type="text" name="username" id="username" class="form-control ewControl"
value="@_login.Username" placeholder="@Language.Phrase("Username")" autocomplete="username">
</div>
</div>
<div class="form-group">
<div><input type="password" name="password" id="password" class="form-control ewControl"
placeholder="@Language.Phrase("Password")" autocomplete="current-password"></div>
</div>
<div class="checkbox">
<label for="rememberme"><input type="checkbox" name="type" id="rememberme" value="a"
@Html.Raw((_login.LoginType == "a") ? " checked" : "")>@Html.Raw(Language.Phrase("RememberMe"))
</label>
</div>
<button class="btn btn-primary btn-block ewButton" name="btnsubmit" id="btnsubmit"
type="submit">@Html.Raw(Language.Phrase("Login"))
</button>
@if (Config.Authentications.Count(kvp => kvp.Value.Enabled) > 0)
{
<div class="social-auth-links text-center">
<p>@Html.Raw(Language.Phrase("LoginOr"))</p>
@foreach (var kvp in Config.Authentications.Where(kvp => kvp.Value.Enabled))
{
<a href="ExternalLogin?provider=@kvp.Key" class="btn btn-block btn-social btn-flat btn-
@kvp.Key.ToLower()">class="fa fa-@kvp.Key.ToLower()">@Html.Raw(Language.Phrase("Login"
+ kvp.Key))</a>
}
</div>
}
<a href= 'login?expire="@_login.Username"' class="btn btn-ic btn-link pkg-photo">Olvide mi clave</a>
</div>
</div>
The .cs is:
public IActionResult Page_Main() {
Username = ""; // Initialize
string password = "";
string lastUrl = Security.LastUrl; // Get last URL
if (Empty(lastUrl))
lastUrl = "Index";
// Login
if (IsLoggingIn()) { // After changing password
{
Username = Session.GetString(Config.SessionUserProfileUserName);
password = Session.GetString(Config.SessionUserProfilePassword);
} else { // Normal login
if (!Security.IsLoggedIn)
Security.AutoLogin();
Security.LoadUserLevel(); // Load user level
bool encrypted = false;
if (!Empty(Post("username"))) {
// Login by form post
Username = RemoveXss(Post("username"));
//Here the error, we sent 1, which it is passed, but the username is lost even you type, so the if (!Empty(Post(Username))) it is never executed
if (Get<bool>("expire"))
{
if (!Empty(Post(Username)))
{
|
|
|
|
|
First use the browser's development tool to check the data going from the browser to the backend - does it contain the username in the format you expect - if not, doublecheck the generated html (again, the browser will let you examine this). If the username is included, you need to debug the server side. It seems it wants to read the username from the season - so put a breakpoint ok n the code putting the username in the session in the first place... Does it even execute?
|
|
|
|
|
I'm creating a program for my school and I have the majority of the bugs fixed but I'm stuck on one part that I can seem to get the timer to stay active after the program is closed. This program allows the user to enter mins and seconds for a timer so they can complete tasks in time but each time the program is closed the timer resets to 0. Is there a way I can make it so maybe when they close the software it doesn't really close it but minimizes it so the timer can continue to run?
|
|
|
|
|
It depends on what you are actually trying to do with your timer: you can't set up a timer within your application and have it run after the app is closed, so it you are doing this to "time" an exam or similar, then it's totally the wrong approach as it's very simple to bypass - bring up task manager and terminate the app process.
So you need to think about exactly what you are trying to use the timer for: what purpose does it serve? What should happen when it expires? What if the use logs out? Turns off the computer? Runs two copies of the app?
There are ways - pretty simple ones - to say "this task must be completed by hh:mm today" and persist that between runs of the app, but that may not be appropriate, depending on your use case.
Similarly, there are ways to minimize the app when it's told to close - but those are nothing like infalible so again, it depends on your use case if that is appropriate.
And we have no idea what you are trying to do with this - we have no access to your system, and only get exactly what you type to work with!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Before we can answer your question, you really need to tell us what type of application this is. Is it a console application? A WPF application? WinForms? WinUI?
|
|
|
|
|
If you're using one of the Timer classes in .NET, you have a serious misunderstanding of how timers work and a serious design flaw in your program.
Any of the Timers you use in the .NET Framework are objects in your code. When your application quits, it's no longer in memory and all of the objects you allocated are destroyed, including the Timer. It doesn't "reset to 0". It's destroyed entirely!
|
|
|
|
|
You can "close" a (Windows) program; minimize (or maximize) it; or hide it, which includes moving it "off screen" or setting its .Visible property to false. Of all those, in your case, you do not want to "close" your program (because that "stops" it).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I am working with EFT solutions in the LSRetail LSOne POS, and one of my customers has an issue that I cannot figure out why happens.
I have a class that has the following declaration:
public class MyEFTService : EFTBase, IEFTService, IMyInterface
{
}
The IMyInterface interface is one I have added so I can execute some added functionality to the class from another location. I do that like this:
public IPosTransaction RunTask()
{
var service = Services.EFTService(entry);
var dxcpcEft = (IMyInterface)service;
}
The Services.EFTService(entry) call returns the instance of MyEFTService created during startup, which I then cast to my IMyInterface and I can then do the calls I need to. This works on my machine, on my testers machine, and any co-workers machine. But it's here my customer has an issue. When we try to cast the instance to the IMyInterface interface on his machine we get an InvalidCastException. In debug, if I look at the service variable and browse through the object information, I can see variables that only my version of EFTBase has and I then know that it does have the IMyInterface as well.
We also tried to execute service is IMyInterface in the immediate debug window of visual studio and it returns true. So, as far as I can see, the service variable DOES have the IMyInterface and visual studios Immediate debug window confirms it. We also tried to run service.GetType(), and that too returns information related to MyEFTService class:
{Name = "EFTService" FullName = "LSOne.Services.EFT.EFTService"}
Assembly: {LSOne.Services.EFT.MY_EFT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}
AssemblyQualifiedName: "LSOne.Services.EFT.MyEFTService, LSOne.Services.EFT.MY_EFT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
Attributes: Public | BeforeFieldInit
BaseType: {Name = "EFTBase" FullName = "LSOne.Services.EFT.Common.EFTBase"}
ContainsGenericParameters: false
CustomAttributes: Count = 0
DeclaredConstructors: {System.Reflection.ConstructorInfo[1]}
DeclaredEvents: {System.Reflection.EventInfo[0]}
DeclaredFields: {System.Reflection.FieldInfo[15]}
DeclaredMembers: {System.Reflection.MemberInfo[75]}
DeclaredMethods: {System.Reflection.MethodInfo[52]}
DeclaredNestedTypes: {System.Reflection.TypeInfo.<get_DeclaredNestedTypes>d__23}
DeclaredProperties: {System.Reflection.PropertyInfo[3]}
DeclaringMethod: '((System.RuntimeType)service.GetType()).DeclaringMethod' threw an exception of type 'System.InvalidOperationException'
DeclaringType: null
FullName: "LSOne.Services.EFT.MyEFTService"
GUID: {2804dbd4-c09a-3951-820b-ce4db1b72a55}
GenericParameterAttributes: '((System.RuntimeType)service.GetType()).GenericParameterAttributes' threw an exception of type 'System.InvalidOperationException'
GenericParameterPosition: '((System.RuntimeType)service.GetType()).GenericParameterPosition' threw an exception of type 'System.InvalidOperationException'
GenericTypeArguments: {System.Type[0]}
GenericTypeParameters: {System.Type[0]}
HasElementType: false
ImplementedInterfaces: {System.Type[3]}
IsAbstract: false
IsAnsiClass: true
IsArray: false
IsAutoClass: false
IsAutoLayout: true
IsByRef: false
IsCOMObject: false
IsClass: true
IsConstructedGenericType: false
IsContextful: false
IsEnum: false
IsExplicitLayout: false
IsGenericParameter: false
IsGenericType: false
IsGenericTypeDefinition: false
IsImport: false
IsInterface: false
IsLayoutSequential: false
IsMarshalByRef: false
IsNested: false
IsNestedAssembly: false
IsNestedFamANDAssem: false
IsNestedFamORAssem: false
IsNestedFamily: false
IsNestedPrivate: false
IsNestedPublic: false
IsNotPublic: false
IsPointer: false
IsPrimitive: false
IsPublic: true
IsSealed: false
IsSecurityCritical: true
IsSecuritySafeCritical: false
IsSecurityTransparent: false
IsSerializable: false
IsSpecialName: false
IsUnicodeClass: false
IsValueType: false
IsVisible: true
MemberType: TypeInfo
MetadataToken: 33554438
Module (System.Reflection.MemberInfo): {LSOne.Services.EFT.MY_EFT.dll}
Module: {LSOne.Services.EFT.MY_EFT.dll}
Name: "MyEFTService"
Namespace: "LSOne.Services.EFT"
ReflectedType: null
StructLayoutAttribute: {System.Runtime.InteropServices.StructLayoutAttribute}
TypeHandle: {System.RuntimeTypeHandle}
TypeInitializer: null
UnderlyingSystemType: {Name = "EFTService" FullName = "LSOne.Services.EFT.EFTService"}
But when we try to code line that casts to the interface, the code fails with an InvalidCastException. We briefly thought that the POS system might not have loaded MyEftService correctly, but we can do operations on it without any issue, so that is not the case.
How come that, on my customer's machine, it cannot cast the service variable to IMyInterface, when all investigations indicate that the service variable does contain an object that inherits IMyInterface, and it works on any other machine? Do you have any suggestions that we can try out?
I am aware that the code is not particularly "safe" in terms of casting and should probably be protected some more. That is in the works.
|
|
|
|
|
I'd start by checking if the customer has all the right dependencies - if the interface or class is declared in a separate assembly (and it probably should be) then a version mismatch could cause the problem.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I thought I did confirm the versions, but it does look like there is a version mismatch with at least some files. I will update when I have more information.
|
|
|
|
|
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Upon further research, it became clear that the versions of the POS system did not match the expected version. We transferred the source code over to the customer so he could build the files with his version and to great care in deleting all other versions of the affected DLL. We still get the same results. I also found the version on my machine that they actually got from me and ran a test on my machine, and it works without problems.
So now to rule out a problem on the customer's end, he is currently sending me the entire software catalogue with my file changes to see if it crashes on my machine. If it fails, it's something in his project. If it does not fail... then I actually don't know. I will keep you posted.
|
|
|
|
|
Sound like you're going to need a site visit with a copy of VS ... I hate those.
I once spent a week sitting quietly in a library waiting for software to go wrong, only to find on the Friday it was a hardware problem: they had a laminator they used to seal new user badges which spat so much noise back down the mains lead it fritzed out the PSU.
Still, it was on expenses, and the hotel bar was good!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Easy way to prevent it in the future; make a hash from all that you build.
Do not confirm the versions, confirm the resulting hash.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
0) Ensure than their machine is up to date on their Windows updates.
1) Have the customer uninstall it (and all older versions), and reinstall it.
".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 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I want to get the control for passing the ticket number in the search bar and update the work notes field and need to change the state field to resolved and click on the update button in servicenow. I have tried but it shows (no such element found exception). kindly help me in this case. I have attached the sample code that I have tried.I have used seleniumc#. I have tried many ways but still getting no such element found exception. kindly some one help me in this case.I want in c#.
Below one is the sample code which i have tried
IWebElement elem = driver.FindElement(By.Id("sysparm_search"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView();", elem);
elem.SendKeys("INC0008111");
elem.SendKeys(Keys.Enter);
WebDriverWait wait2 = new WebDriverWait(driver,TimeSpan.FromSeconds(20));
wait.Until(ExpectedConditions.ElementExists(By.Id("activity-stream-textarea")))
wait2.SendKeys("closing the request");
SelectElement se = new
SelectElement(driver.FindElement(By.Name("incident.state")));
se.SelectByIndex(3); IWebElement ele4 =
driver.FindElement(By.Id("resolve_incident")); ele4.Click();
|
|
|
|
|
The first thing to do is to use the debugger to find out which element is not found.
Then you can start looking through your design to find out why: but since we have no access to your code while it is running or your design at all there is nothing we can do to help.
Just "trying many ways" doesn't help you - you need to think logically and gather information before you start modifying code. Without doing that, you are just guessing, and that isn't an efficient 9or effective) way to fix any problem! Gathering information on a problem is what the debugger is there for - so use it!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
In my project, i was used a control of PropertyGrid, and i bind a object(the instance of my class). The drop-down list-box item of propertygrid could be drop down only once. there is nothing showing when i click the drop-down button again.(the list item just like bool, enum variables) And surprisedly, i can't close this window.
So, help me, please...
a poor guy diging C#
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
So start with the code: what are you doing when it drops down? How are you binding it? What does your class contain? What is it derived from? Do you override ToString? Anything else that might be relevant?
Only you can look at things like this: we can have no idea without much, much better information!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Works for me, even on Linux using mono.
Can you post some code to reproduce the problem?
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I have requirement where we have 2 exe's. When first exe started then I have to call method of second exe which will do some process. once that process is completed then it again intimates first exe that my work is done. you can resume your work.
Note: I do not want to use sockets. Most preferred way is like Mutex or Semaphore.
Any help will be much appreciated.
|
|
|
|
|