Click here to Skip to main content

C#

   
Home > Forums > C#

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page  Show 
  Refresh
GeneralRe: To filter datagridview using like IN and NOT IN PinmvpAbhinav S0:00 23 Feb '12  
GeneralRe: To filter datagridview using like IN and NOT IN PinmemberMember 45661670:13 23 Feb '12  
AnswerRe: To filter datagridview using like IN and NOT IN PinmemberMember 45661670:23 23 Feb '12  
AnswerRe: To filter datagridview using like IN and NOT IN PinmemberAntDC5:37 23 Feb '12  
QuestionOptions to check logical equivalence of Boolean expressions Pinmemberraj_2820:16 22 Feb '12  
AnswerRe: Options to check logical equivalence of Boolean expressions PinmvpAbhinav S20:54 22 Feb '12  
QuestionHow can I to manipulate dynamically created controls? PinmemberNWNewelll10:42 22 Feb '12  
Lets say I have a form where someone can catalog a multiple people's Name and their State and City?
 
Assume I already have all the State/Cities in database. (a table for each state, with cities listed in each table)
 
The Name field will be a TextBox. And the State & City fields will be ComboBox (DropDownLists).
 
One row (for the entry of one person) already exists in the form. But I want the user to be able to dynamically add rows of entries by pressing an "Add Person" button.
 
The next step is where I'm struggling. In each dynamically added row of fields, I would like the second ComboBox (Cities) to be populated depending on which State is chosen in the first Combo Box. Also, the Cities ComboBox will remain disabled until the State ComboBox is chosen.
 
My code looks something like this:
 
    public ComboBox cbState;
    public ComboBox cbCities;
    public static int NumberOfPeople = 1;
 

    private void btnAddNewPerson_Click(object sender, EventArgs e)
    {
 
        NumberOfPeople++;
 
        TextBox txtPerson = new TextBox();
        txtPerson.Name = "Person" + NumberOfPeople;
        Panel.Controls.Add(txtPerson);
 
        //  ADD State ComboBox
        cbState = new ComboBox();
        cbState.Name = "State" + NumberOfPeople;
        cbState.Enabled = true;
        cbState.DropDownStyle = ComboBoxStyle.DropDownList;
        Panel.Controls.Add(cbState);
 
        //  ADD City ComboBox
        cbCity = new ComboBox();
        cbCity.Name = "City" + NumberOfPeople;
        cbCity.DropDownStyle = ComboBoxStyle.DropDownList;
        cbCity.Enabled = false;
        cbCity.SelectedValueChanged += new System.EventHandler(this.ChangeState);
        Panel.Controls.Add(cbCity);
 
    }
 
    private void ChangeState(object sender, EventArgs e)
    {
 
       ..... Don't know how to properly identify the dynamically created City ComboBox that is in the same row as the State ComboBox that was just changed, and manipulate/populate it.....
 
    }
 
Anyone able to help me solve this issue??
 
I'd greatly appreciate it!!
AnswerRe: How can I to manipulate dynamically created controls? PinmemberPIEBALDconsult11:04 22 Feb '12  
AnswerRe: How can I to manipulate dynamically created controls? PinmemberBobJanova22:57 22 Feb '12  
AnswerRe: How can I to manipulate dynamically created controls? PinmemberGParkings23:00 22 Feb '12  
AnswerRe: How can I to manipulate dynamically created controls? [modified] PinmemberBillWoodruff15:00 24 Feb '12  
QuestionHow can we access to an object of a form from another form? Pinmemberfaraz349:59 22 Feb '12  
AnswerRe: How can we access to an object of a form from another form? PinmemberPIEBALDconsult10:09 22 Feb '12  
GeneralRe: How can we access to an object of a form from another form? Pinmemberfaraz3411:53 22 Feb '12  
AnswerRe: How can we access to an object of a form from another form? PinassociateWes Aday10:32 22 Feb '12  
GeneralRe: How can we access to an object of a form from another form? Pinmemberfaraz3411:51 22 Feb '12  
AnswerRe: How can we access to an object of a form from another form? PinmvpLuc Pattyn12:12 22 Feb '12  
AnswerRe: How can we access to an object of a form from another form? Pinmemberhellono120:50 22 Feb '12  
AnswerRe: How can we access to an object of a form from another form? PinmemberQuintain15:03 26 Feb '12  
QuestionRegarding AttributeUsageAttribute.AllowMultiple PinmemberPIEBALDconsult8:11 22 Feb '12  
QuestionHow to check that dsn which is created used for Sql Server or Access using C# PinmemberAwadhendra12342:16 22 Feb '12  
AnswerRe: How to check that dsn which is created used for Sql Server or Access using C# PinmemberPIEBALDconsult2:56 22 Feb '12  
GeneralRe: How to check that dsn which is created used for Sql Server or Access using C# PinmemberAwadhendra12343:24 22 Feb '12  
GeneralRe: How to check that dsn which is created used for Sql Server or Access using C# PinmemberPIEBALDconsult4:00 22 Feb '12  
QuestionDetect Marked Checkbox using OCR Pinmemberzead2:12 22 Feb '12  

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

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


Advertise | Privacy | Mobile
Beta | 2.5.120517.1 | Last Updated 23 May 2012
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid