473,804 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

comboBox SelectedIndexCh anged fires 4 time on load

is there a way to stop combox from firing SelectedIndexCh anged events
on loading when it is databinded?

everytime my form loads, SelectedIndexCh anged fires 4 times?

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;

namespace TestCombobox
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.ComboBox comboBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent
call
//
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("Col 1");
dt.Columns.Add( dc);

DataRow r1 = dt.NewRow();
r1["Col1"] = "a";
DataRow r2 = dt.NewRow();
r2["Col1"] = "b";
DataRow r3 = dt.NewRow();
r3["Col1"] = "c";

dt.Rows.Add(r1) ;
dt.Rows.Add(r2) ;
dt.Rows.Add(r3) ;

this.comboBox1. DataSource = new string[] {"a", "b", "c"};
this.comboBox1. DataBindings.Ad d("Text", dt, "Col1");

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.comboBox1 = new System.Windows. Forms.ComboBox( );
this.SuspendLay out();
//
// comboBox1
//
this.comboBox1. Location = new System.Drawing. Point(56, 88);
this.comboBox1. Name = "comboBox1" ;
this.comboBox1. Size = new System.Drawing. Size(121, 21);
this.comboBox1. TabIndex = 0;
this.comboBox1. Text = "comboBox1" ;
this.comboBox1. SelectedIndexCh anged += new
System.EventHan dler(this.combo Box1_SelectedIn dexChanged);
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 266);
this.Controls.A ddRange(new System.Windows. Forms.Control[] {

this.comboBox1} );
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayo ut(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new Form1());
}

private void comboBox1_Selec tedIndexChanged (object sender,
System.EventArg s e)
{
Console.WriteLi ne("CHANGED");
}
}
}
Nov 16 '05 #1
0 2108

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1378
by: jcb1269 | last post by:
How do you select an item in a combobox. I've tried the Click events and that works only when I actually click the combobox. I want to select an item in the combbox not the combbox itself. Any ideas?? Thanks.. Jim
4
4020
by: Keith | last post by:
Hello - this started out as a minor annoyance - and now is starting to bother me more and more - I'm hoping someone can help me. I would like to have a combobox display - NOT initially be blank - but contain a value. However the value is just for user reference - not really one of the combobox choices. For example intially the combobox should equal the word Select - and the item values can be say 'one', 'two', and 'three'.
2
3694
by: blue_nirvana | last post by:
I use a AddHandler statement in the load event of a form to assoicate a routine with a combobox. When I populate the form, I select the approiate value from the combobox by using combobox.selectedvalue = value. The weird thing is sometimes this causes the assoicated routine to be called and sometimes it does not. The combobox below it that is completely identical except for the name works every time. After the form is displayed, you can...
2
3922
by: Steve F. | last post by:
I have a problem. I use a combobox in my datagrid, but I noticed, as soon as the user clicks on the field where the combobox, the event fires with a index value of 0, then of course with the selected index value as it should. But why is it firing the first time. How do I make it stop. Please advice. Thank You, Steve http://www.ItsMoreThanSoftware.com
8
2075
by: Dennis D. | last post by:
Preface: I have viewed the combobox control video at Microsoft.at the movies. I want to simulate an HTML combobox as a windows application combobox with 5 to 10 selections in each box. In the HTML form: <option value="help.htm">More Info</option> Thing is: I want to put the URL description "More Info" into the combobox list, not the URL "help.htm."
4
8508
by: Joe Schmoe | last post by:
All I want to to be able to take a two-column DataReader (One column with the Item ID number, the other with Item Description text) and load it into a Windows Forms ComboBox (Set to DropDownList mode) so that I the dropdown shows the Item Descriptions, but returns the Item ID number when selected. Completely easy in ASP.NET, but I cannot figure out how to do the same in a Windows Forms app. Obviously the Windows Forms ComboBox is a lot more...
6
10824
by: tbrown | last post by:
I have a combobox with items like this: {one,two,three}. The selected index is 0, so "one" appears in the combobox text. When the user drops down the list, and selects "two", for example, I modify the Items collection to be {two,one,three} and now want "two" to appear in the combobox text. However, the combobox text is now blank. the is apparently somehow the result of having changed the combobox.Items collection. If, trying to fix...
2
2974
by: tshad | last post by:
In my VS 2003 Windows Forms page, when I initially fill my ComboBox (SystemList), it goes to the SelectedIndexChanged event which calls the Loademails() function. I then call it again in the Form1Load function. How do I get it not to call it in the SelectedIndexChanged from the Form1Load function? Normally, I want it to call it but not when I initally fill the ComboBox. *********************************************************...
4
3365
by: somacore | last post by:
Quick question, Is there a way to preserve the value in my combobox when it fires a SelectedIndexChanged event? Right now I have 4 comboboxes all linked together with an SQL query: Site City Manager name Phone number
0
10594
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10087
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7631
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.