Click here to Skip to main content
15,176,980 members
Home / Discussions / C#
   

C#

 
AnswerRe: Pass field Pin
Richard Deeming3-Dec-21 3:56
mveRichard Deeming3-Dec-21 3:56 
Questionthread safety and performance Pin
Super Lloyd2-Dec-21 16:31
MemberSuper Lloyd2-Dec-21 16:31 
GeneralRe: thread safety and performance Pin
harold aptroot2-Dec-21 17:03
Memberharold aptroot2-Dec-21 17:03 
GeneralRe: thread safety and performance Pin
Super Lloyd2-Dec-21 18:59
MemberSuper Lloyd2-Dec-21 18:59 
AnswerRe: thread safety and performance Pin
trønderen3-Dec-21 3:36
Membertrønderen3-Dec-21 3:36 
AnswerRe: thread safety and performance Pin
trønderen3-Dec-21 4:31
Membertrønderen3-Dec-21 4:31 
QuestionUpdate/refresh Combobox in Form1 after doing an add from Form 2 Pin
Richard A Knox2-Dec-21 6:19
MemberRichard A Knox2-Dec-21 6:19 
AnswerRe: Update/refresh Combobox in Form1 after doing an add from Form 2 Pin
BillWoodruff2-Dec-21 6:58
mveBillWoodruff2-Dec-21 6:58 
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:

C#
// in Form1
// after you create a new instance of Form2
Form2 f2 = new Form2();
// add the handler
f2.AddCreditorName += UpdateComboBox;

public void UpdateComboBox(string newCreditorName)
{
     // add validation here ? check for duplicate names ?
     comboBox1.Items.Add(newCreditorName);
}

// in Form2

// public delegate takes one parameter of type 'string and returns void
public Action<string> AddCreditorName = null;

// when Form2 is complete ... all the information is entered/validated
// in the Click handler for Form2's 'Save button
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

GeneralRe: Update/refresh Combobox in Form1 after doing an add from Form 2 Pin
Richard A Knox4-Dec-21 7:08
MemberRichard A Knox4-Dec-21 7:08 
GeneralRe: Update/refresh Combobox in Form1 after doing an add from Form 2 Pin
Gerry Schmitz5-Dec-21 9:04
mveGerry Schmitz5-Dec-21 9:04 
QuestionReading username Pin
Luis M. Rojas1-Dec-21 5:45
MemberLuis M. Rojas1-Dec-21 5:45 
AnswerRe: Reading username Pin
lmoelleb3-Dec-21 19:36
Memberlmoelleb3-Dec-21 19:36 
QuestionHow can I make the timer stay active after the program is closed? Pin
Duke Jason30-Nov-21 20:34
MemberDuke Jason30-Nov-21 20:34 
AnswerRe: How can I make the timer stay active after the program is closed? Pin
OriginalGriff30-Nov-21 21:09
mveOriginalGriff30-Nov-21 21:09 
AnswerRe: How can I make the timer stay active after the program is closed? Pin
Pete O'Hanlon30-Nov-21 22:24
mvaPete O'Hanlon30-Nov-21 22:24 
AnswerRe: How can I make the timer stay active after the program is closed? Pin
Dave Kreskowiak1-Dec-21 2:20
mveDave Kreskowiak1-Dec-21 2:20 
AnswerRe: How can I make the timer stay active after the program is closed? Pin
Gerry Schmitz1-Dec-21 19:09
mveGerry Schmitz1-Dec-21 19:09 
QuestionCode cast InvalidCastException when it "Shouldn't" Pin
Evilfish200029-Nov-21 20:28
MemberEvilfish200029-Nov-21 20:28 
AnswerRe: Code cast InvalidCastException when it "Shouldn't" Pin
OriginalGriff29-Nov-21 22:24
mveOriginalGriff29-Nov-21 22:24 
GeneralRe: Code cast InvalidCastException when it "Shouldn't" Pin
Evilfish200030-Nov-21 3:24
MemberEvilfish200030-Nov-21 3:24 
GeneralRe: Code cast InvalidCastException when it "Shouldn't" Pin
OriginalGriff30-Nov-21 3:50
mveOriginalGriff30-Nov-21 3:50 
GeneralRe: Code cast InvalidCastException when it "Shouldn't" Pin
Evilfish200030-Nov-21 23:05
MemberEvilfish200030-Nov-21 23:05 
GeneralRe: Code cast InvalidCastException when it "Shouldn't" Pin
OriginalGriff30-Nov-21 23:19
mveOriginalGriff30-Nov-21 23:19 
GeneralRe: Code cast InvalidCastException when it "Shouldn't" Pin
Eddy Vluggen30-Nov-21 9:02
professionalEddy Vluggen30-Nov-21 9:02 
AnswerRe: Code cast InvalidCastException when it "Shouldn't" Pin
#realJSOP30-Nov-21 0:25
mva#realJSOP30-Nov-21 0:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.