Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
guys i am having an unusual problem with a combo box
i have set a datasource for my combo box to display values in a table (oledb)
when i compile program it runs correctly and combo box shows the data
but when i select another value in combo box, it replaces the first value
for example my items are :

Dog
Cat
Monkey
Lion

when i select "Monkey" in combo box (in compile), then it becomes like this :

Monkey
Cat
Monkey
Lion

what should i do ?

[no coding involved here just drag and drop]
Posted
Comments
Aydin Homay 7-Jul-13 5:09am    
Could you post your combo box binding and combo box properties code here ?
Ankush Bansal 7-Jul-13 10:46am    
Looks like something is fishy in your datasource... can you post some code ?

1 solution

try this code


Quote:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace combox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

string str = "";
OleDbCommand com;
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(@"put your connection string");
con.Open();

// select query which fetch record to bind in combobox
str = "select * from tbl_name";

com = new OleDbCommand(str, con);

OleDbDataReader reader = com.ExecuteReader();

while (reader.Read())

{// replace your combobox name
comboBox1.Items.Add(reader["name"]);
}
reader.Close();
con.Close();
}
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900