Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Add Items In The Combobox

combobox

  • Please log in to reply
3 replies to this topic

#1 percis

percis

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 72 posts
  • Programming Language:C
  • Learning:C#, (Visual) Basic

Posted 24 July 2012 - 06:13 PM

private void cbb_NumberofDaysofAutonomy_SelectedIndexChanged(object sender, EventArgs e)
	  {
	   
		 if (radioButton1.Checked == true)
		 {
		    cbb_NumberofDaysofAutonomy.Items.Add(1);
		    cbb_NumberofDaysofAutonomy.Items.Add(2);
		    cbb_NumberofDaysofAutonomy.Items.Add(3);
		    cbb_NumberofDaysofAutonomy.Items.Add(4);
		    cbb_NumberofDaysofAutonomy.Items.Add(5);
		 }
		 else if (radioButton2.Checked == true)
		 {
		    cbb_NumberofDaysofAutonomy.Items.Add(6);
		    cbb_NumberofDaysofAutonomy.Items.Add(8);
		    cbb_NumberofDaysofAutonomy.Items.Add(10);
		 }
		 double dblTotalDemand, dblBatteryCapacity;
		 if (txt_AhDemand.Text != "" && cbb_NumberofDaysofAutonomy.Text != "" && cbb_DepthofDischarge.Text != "")
		 {
		    dblTotalDemand = Convert.ToDouble(txt_AhDemand.Text) * Convert.ToDouble(cbb_NumberofDaysofAutonomy.Text);
		    dblBatteryCapacity = dblTotalDemand / Convert.ToDouble(cbb_DepthofDischarge.Text);
		    txt_BatteryCapacity.Text = dblBatteryCapacity.ToString("#");
		 }
	  }
	  private void cbb_DepthofDischarge_SelectedIndexChanged(object sender, EventArgs e)
	  {
		 double dblTotalDemand, dblBatteryCapacity;
		 if (txt_AhDemand.Text != "" && cbb_NumberofDaysofAutonomy.Text != "" && cbb_DepthofDischarge.Text != "")
		 {
		    dblTotalDemand = Convert.ToDouble(txt_AhDemand.Text) * Convert.ToDouble(cbb_NumberofDaysofAutonomy.Text);
		    dblBatteryCapacity = dblTotalDemand / Convert.ToDouble(cbb_DepthofDischarge.Text);
		    txt_BatteryCapacity.Text = dblBatteryCapacity.ToString("#");
		 }
	  }

	  private void txt_AhDemand_TextChanged(object sender, EventArgs e)
	  {
	  }

when either radiobutton1 or radiobutton 2 checked but no items added in the combobox of " cbb_NumberofDaysofAutonomy".
what's the mistake? code?
Thanks.
  • 0

#2 mohax

mohax

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts
  • Programming Language:C
  • Learning:C

Posted 25 July 2012 - 12:04 AM

private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
{
cbb_NumberofDaysofAutonomy.Items.Add(6);
cbb_NumberofDaysofAutonomy.Items.Add(8);
cbb_NumberofDaysofAutonomy.Items.Add(10);
}
}

private void radioButton1_CheckedChanged(object sender, EventArgs e)
		{
			if (radioButton1.Checked == true)
			{
				cbb_NumberofDaysofAutonomy.Items.Add(1);
				cbb_NumberofDaysofAutonomy.Items.Add(2);
				cbb_NumberofDaysofAutonomy.Items.Add(3);
				cbb_NumberofDaysofAutonomy.Items.Add(4);
				cbb_NumberofDaysofAutonomy.Items.Add(5);
			}
		}

  • 1

#3 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 25 July 2012 - 12:06 AM

I don't understand your logic's here. Are you changing the possible options of the select when a option is selected?
In my world, the change of available options for the select should be on a change event on the radio buttons...
  • 1

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#4 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 26 July 2012 - 03:34 AM

Are you sure that one of the two is selected during the execution of cbb_NumberofDaysofAutonomy_SelectedIndexChanged method?
Note that there are chances that none of the radio buttons are selected. As example, at start up no radio buttons will be selected (assumed you have not selected any one programmatically) until you select one manually after lunching.
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download