Click here to Skip to main content
15,883,705 members
Home / Discussions / C#
   

C#

 
AnswerRe: To filter datagridview using like IN and NOT IN Pin
AntDC23-Feb-12 5:37
AntDC23-Feb-12 5:37 
QuestionOptions to check logical equivalence of Boolean expressions Pin
raj_2822-Feb-12 20:16
raj_2822-Feb-12 20:16 
AnswerRe: Options to check logical equivalence of Boolean expressions Pin
Abhinav S22-Feb-12 20:54
Abhinav S22-Feb-12 20:54 
QuestionHow can I to manipulate dynamically created controls? Pin
NWNewelll22-Feb-12 10:42
NWNewelll22-Feb-12 10:42 
AnswerRe: How can I to manipulate dynamically created controls? Pin
PIEBALDconsult22-Feb-12 11:04
mvePIEBALDconsult22-Feb-12 11:04 
AnswerRe: How can I to manipulate dynamically created controls? Pin
BobJanova22-Feb-12 22:57
BobJanova22-Feb-12 22:57 
AnswerRe: How can I to manipulate dynamically created controls? Pin
GParkings22-Feb-12 23:00
GParkings22-Feb-12 23:00 
AnswerRe: How can I to manipulate dynamically created controls? Pin
BillWoodruff24-Feb-12 15:00
professionalBillWoodruff24-Feb-12 15:00 
You already have three excellent answers from PieBaldConsult, BobJanova, and GParkings that each give you valuable insights, and strategies.

While I'm not sure why PieBaldConsult why considers a DataGridView a "poor design" in this particular scenario: and, I have to confess my bias: I just hate the DataGridView, and think it's an ugly thing, so in that sense I certainly agree you should not use it. I also like PBC's idea of using a dialog (or pop-up Form) which gives the user the option to Cancel, before automatically adding another "virtual row of Controls" to your Panel.

If you automatically add a new 'Person object, and the user decides they really didn't want to do that: what do you do now: can the user delete a selected 'Person object: if so, how ?

But, the larger question I have about your design here is what appears to be the absence of your using a database to write and store, at some point, the collection of 'Person objects. You already use database tables for State/City correlations. Can we assume that, at some point, you are going to enumerate the list of 'Person objects and write them to a database ?

And, I'd like to respond to your question exactly as asked: your code shows you are creating three new controls, with each addition of a new user, and adding them to the Panel.

A better strategy, imho, is to create a UserControl that has all three controls, and add a new one of those with each click of the 'Add Person' button to the Panel: by using docking properly, and setting z-order, they'll form an ordered list, naturally, and you can set scrollbars in the Panel to visible for easy access to the whole list, should it overflow the Panel bounds.

Note that using UserControls would handle the problem of deleting entries easily: since you can maintain a "currently selected 'Person instance" variable that contains a reference to the UserControl that currently has "Focus."

Within the UserControl, you can have a public property for each of the three Controls, whose value is set to the instance of the Control, in the UserControl 'Load event, and thus are easily accessible from your Panel, or its containing Form. Or, for more limited exposure (parsimony): have the three public properties be only the text value of the UserName control, and the ComboBox Index properties of the State and City objects.

imho, Events come into play here when someone changes their choices for values in the three "field entry" facilities. And, imho, Bob Janova, covers that exhaustively in his answer. I've had such a negative experience using PropertyNotification in WinForms, that I'd handle this by invoking static methods in a static class to update, but perhaps my thorough study of Bob's example ... which is going to happen ... will straighten my head out about PropertyNotification, and I'll have a "conversion experience" Smile | :)

The question of how the newly created 'Person object "inherits" the last State name used is easily solved by having a variable of Type int (or you could be using an Enum) called 'LastStateSpecified, or whatever: set it every time the act of adding a new 'Person object is completed, and the State field is set. Then, when you create the next 'Person object: use the value of that variable ...as the Combobox Index ... to set the new ComboBox to the correct State.

best, Bill
"Every two days we create as much information as we did from the dawn of civilization up until 2003". Eric Schmidt of Google.


modified 25-Feb-12 2:40am.

QuestionHow can we access to an object of a form from another form? Pin
Fred 3422-Feb-12 9:59
Fred 3422-Feb-12 9:59 
AnswerRe: How can we access to an object of a form from another form? Pin
PIEBALDconsult22-Feb-12 10:09
mvePIEBALDconsult22-Feb-12 10:09 
GeneralRe: How can we access to an object of a form from another form? Pin
Fred 3422-Feb-12 11:53
Fred 3422-Feb-12 11:53 
AnswerRe: How can we access to an object of a form from another form? Pin
Wes Aday22-Feb-12 10:32
professionalWes Aday22-Feb-12 10:32 
GeneralRe: How can we access to an object of a form from another form? Pin
Fred 3422-Feb-12 11:51
Fred 3422-Feb-12 11:51 
AnswerRe: How can we access to an object of a form from another form? Pin
Luc Pattyn22-Feb-12 12:12
sitebuilderLuc Pattyn22-Feb-12 12:12 
AnswerRe: How can we access to an object of a form from another form? Pin
hellono122-Feb-12 20:50
hellono122-Feb-12 20:50 
AnswerRe: How can we access to an object of a form from another form? Pin
Quintain26-Feb-12 15:03
Quintain26-Feb-12 15:03 
QuestionRegarding AttributeUsageAttribute.AllowMultiple Pin
PIEBALDconsult22-Feb-12 8:11
mvePIEBALDconsult22-Feb-12 8:11 
QuestionHow to check that dsn which is created used for Sql Server or Access using C# Pin
Awadhendra123422-Feb-12 2:16
Awadhendra123422-Feb-12 2:16 
AnswerRe: How to check that dsn which is created used for Sql Server or Access using C# Pin
PIEBALDconsult22-Feb-12 2:56
mvePIEBALDconsult22-Feb-12 2:56 
GeneralRe: How to check that dsn which is created used for Sql Server or Access using C# Pin
Awadhendra123422-Feb-12 3:24
Awadhendra123422-Feb-12 3:24 
GeneralRe: How to check that dsn which is created used for Sql Server or Access using C# Pin
PIEBALDconsult22-Feb-12 4:00
mvePIEBALDconsult22-Feb-12 4:00 
QuestionDetect Marked Checkbox using OCR Pin
Zeyad Jalil22-Feb-12 2:12
professionalZeyad Jalil22-Feb-12 2:12 
AnswerRe: Detect Marked Checkbox using OCR PinPopular
enhzflep22-Feb-12 4:44
enhzflep22-Feb-12 4:44 
GeneralRe: Detect Marked Checkbox using OCR Pin
Zeyad Jalil22-Feb-12 20:29
professionalZeyad Jalil22-Feb-12 20:29 
GeneralRe: Detect Marked Checkbox using OCR Pin
enhzflep22-Feb-12 20:43
enhzflep22-Feb-12 20:43 

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.