in my application i have one combobox and button
when i click button it needs to generate a code like C001,C002,etc.
how to do this?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 25, 2015, 10:34 PM EDT
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Mar 25, 2015, 10:05 PM EDT
static int Num = 0;
string Str = "C00";
string Stm;
private void button1_Click(object sender, EventArgs e)
{
Num++;
Stm = Str + Num.ToString();
MessageBox.Show(Stm);
}
Ans will be:
C001
C002
C003
-
-
-
-
C0010
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 25, 2015, 10:09 PM EDT
int i=0 string strc00; onbuttonclick { if (i > 0) { int j = i + 1; strc00 = "C00" +j.ToString(); } else { strc00 = "C001"; } i++; }Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Mar 25, 2015, 11:28 PM EDT
string Str = "C00";
string Stm;
private void button1_Click(object sender, EventArgs e)
{
Num++;
Stm = Str + Num.ToString();
ComboBox1.Items.Add(Stm);
}
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 25, 2015, 11:35 PM EDT
Are you developing desktop base application or web base application?
agree with above answer if you are developing desktop application
but approach is different when you use web application because web application is stateless and you have to maintain state by your self
hope this will help you.
Durga VelusamyRank #4,868 · 321 reputationPosted Mar 25, 2015, 10:25 PM EDT
Durga VelusamyRank #4,868 · 321 reputationPosted Mar 25, 2015, 11:49 PM EDT
ok fine . if it textbox means how to give
comboBox1.Items.Add(strc00);