Click here to Skip to main content
15,891,864 members
Home / Discussions / C#
   

C#

 
QuestionData storage and Uploading file Pin
Banjo Ayorinde23-Jul-08 17:13
Banjo Ayorinde23-Jul-08 17:13 
AnswerRe: Data storage and Uploading file Pin
half-life23-Jul-08 19:53
half-life23-Jul-08 19:53 
GeneralRe: Data storage and Uploading file Pin
Abdul Sami X24-Jul-08 20:15
Abdul Sami X24-Jul-08 20:15 
QuestionCopy Dictionay Object To Other [modified] Pin
vaibhav.jape@gmail.com23-Jul-08 13:30
vaibhav.jape@gmail.com23-Jul-08 13:30 
AnswerRe: Copy Dictionay Object To Other Pin
N a v a n e e t h23-Jul-08 17:01
N a v a n e e t h23-Jul-08 17:01 
GeneralRe: Copy Dictionay Object To Other Pin
vaibhav.jape@gmail.com23-Jul-08 17:20
vaibhav.jape@gmail.com23-Jul-08 17:20 
AnswerRe: Copy Dictionay Object To Other [modified] Pin
Elroy Dsilva23-Jul-08 17:10
Elroy Dsilva23-Jul-08 17:10 
AnswerRe: Copy Dictionay Object To Other Pin
Elroy Dsilva23-Jul-08 17:37
Elroy Dsilva23-Jul-08 17:37 
AnswerRe: Copy Dictionay Object To Other Pin
N a v a n e e t h23-Jul-08 19:30
N a v a n e e t h23-Jul-08 19:30 
QuestionHow to access an IEnumerable item using reflection [modified] Pin
Clive D. Pottinger23-Jul-08 12:39
Clive D. Pottinger23-Jul-08 12:39 
AnswerRe: How to access an IEnumerable item using reflection Pin
Luc Pattyn23-Jul-08 13:01
sitebuilderLuc Pattyn23-Jul-08 13:01 
GeneralRe: How to access an IEnumerable item using reflection Pin
Clive D. Pottinger23-Jul-08 13:53
Clive D. Pottinger23-Jul-08 13:53 
GeneralRe: How to access an IEnumerable item using reflection [modified] Pin
Luc Pattyn23-Jul-08 14:52
sitebuilderLuc Pattyn23-Jul-08 14:52 
GeneralRe: How to access an IEnumerable item using reflection Pin
Clive D. Pottinger23-Jul-08 15:44
Clive D. Pottinger23-Jul-08 15:44 
GeneralRe: How to access an IEnumerable item using reflection Pin
Luc Pattyn23-Jul-08 15:51
sitebuilderLuc Pattyn23-Jul-08 15:51 
GeneralRe: How to access an IEnumerable item using reflection Pin
Luc Pattyn23-Jul-08 16:13
sitebuilderLuc Pattyn23-Jul-08 16:13 
GeneralRe: How to access an IEnumerable item using reflection Pin
Luc Pattyn23-Jul-08 15:16
sitebuilderLuc Pattyn23-Jul-08 15:16 
AnswerRe: How to access an IEnumerable item using reflection Pin
Clive D. Pottinger23-Jul-08 14:43
Clive D. Pottinger23-Jul-08 14:43 
GeneralWithout explicit GetEnumerator Pin
Luc Pattyn24-Jul-08 2:19
sitebuilderLuc Pattyn24-Jul-08 2:19 
Questiondropdownlist data fetch Pin
scottichrosaviakosmos23-Jul-08 8:02
scottichrosaviakosmos23-Jul-08 8:02 
GeneralRe: dropdownlist data fetch Pin
nelsonpaixao23-Jul-08 14:43
nelsonpaixao23-Jul-08 14:43 
GeneralRe: dropdownlist data fetch Pin
scottichrosaviakosmos23-Jul-08 17:23
scottichrosaviakosmos23-Jul-08 17:23 
AnswerRe: dropdownlist data fetch [modified] Pin
nelsonpaixao24-Jul-08 13:39
nelsonpaixao24-Jul-08 13:39 
listen, what you request it´s not hard, but it takes lots of time to code and debug!!!
So, read the following and if you became stuck ask here in the forum anyone can help you there stay cool.Cool | :cool:
(i assume you mean that dropdownlist = combobox)



private void Form1_Load(object sender, EventArgs e)
{
textBox1.Visible = false;
comboBox1.Items.Add("ASP"); //0
comboBox1.Items.Add("C#"); //1
comboBox1.Items.Add("VB"); //2
comboBox1.Items.Add("Javascript"); //3
comboBox1.Items.Add("PHP"); //4
comboBox1.Items.Add("Other"); //5
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == 5)
{
textBox1.Visible = true;
}
else
{
textBox1.Visible = false;
}
}

private void button1_Click(object sender, EventArgs e)
{
comboBox1.Items.Add(textBox1.Text);
}



Try that easy exemple but that´s not enought! The solution without using a database doesn´t exist!
How and where would you store the data from new values added to the textbox?
And as you can see, each time you load your application your combox will only have the old values not the new added items. You noticed it already, right?

What you have to do instead is this:

create a table (if you don´t have one already) to fill up the combobox, so when you press button new values from the textbox will be added to the table.


1) create table tech with: id int, name varchar(50)

id | name
1 | ASP
2 | c#
3 | VB
4 | HTML
5 | PHP
6 | C++
...etc

2) create a SQL store procedure to fill up/load your combox (trigger it with a load_form event)

SQL:
create procedure tech_all
as
begin
select id, name from dbo.tech
end
go


C#:
this is what i do to connect to database and fill combobox:

string CONNECTION_STRING = "..."; // you know this

SqlConnection con_sql = new SqlConnection(CONNECTION_STRING);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con_sql;
cmd.CommandText = tech_all; // the store procedure above
cmd.CommandType = CommandType.StoredProcedure;
con_sql.Open();
SqlDataAdapter sql_da = new SqlDataAdapter();
sql_da.SelectCommand = cmd;
DataTable dt = new DataTable();
sql_da.Fill(dt);
con_sql.Close();
COMBOBOX1.DataSource = dt;
COMBOBOX1.DisplayMember = "name"; // table tech variable
COMBOBOX1.ValueMember = "id"; // table tech variable


3)create a SQL SP to add values to your combobox (trigger it with button_click event)

SQL:
create procedure tech_add
@name as varchar(50)
as
begin
insert into dbo.tech (name)
values (@name)
end
go


C#:
this is what i do to connect to database and add values to combobox:
(check this part i didn´t have time to test)

string CONNECTION_STRING = "...";

SqlConnection con_sql = new SqlConnection(CONNECTION_STRING);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con_sql;
cmd.CommandText = tech_add; // the store procedure above
cmd.CommandType = CommandType.StoredProcedure;
//
command.Parameters.Add("@name", SqlDbType.VarChar).Value = textbox1.text; // your input textbox!!!
//
con_sql.Open();
SqlDataAdapter sql_da = new SqlDataAdapter();
sql_da.SelectCommand = cmd;
DataTable dt = new DataTable();
sql_da.Fill(dt);
con_sql.Close();
COMBOBOX1.DataSource = dt;
COMBOBOX1.DisplayMember = "name"; // table tech variable
COMBOBOX1.ValueMember = "id"; // table tech variable



Change anything you like to fit what you have in mind!
Good Luck Big Grin | :-D

modified on Thursday, July 24, 2008 7:54 PM

QuestionProblem booking timeslots within a range of dates Pin
Twyce23-Jul-08 7:18
Twyce23-Jul-08 7:18 
AnswerRe: Problem booking timeslots within a range of dates Pin
Luc Pattyn23-Jul-08 8:01
sitebuilderLuc Pattyn23-Jul-08 8:01 

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.