Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

How to delete a object in c#?

$
0
0

I create two combobox. The first combobox's item from database is fixed. The second combobox's item is also from database.But the item is accordimg to the first combobox item selected. I use "new" to create first combobox item. It's not problem. But when the first combobox item is selected in the second times. I dont know how to delete combobox that is created in the first times. Please give a suggestion. The simplified program code is following. Thanx.

publicpartialclassForm1 :Form

{

     ..................omit......

     ComBoItm cbi_Test;

     ArrayList arylst_Test;

     privatevoid Form1_Load(object sender, EventArgs e)

     {

           cbi_Test = newComBoItm("fruit", 200);

                  

           arylst_Test = newArrayList();

           arylst_Test.Add(cbi_Test);

           comboBox1.DataSource = arylst_Test;

           comboBox1.DisplayMember = "Item_Text";

           comboBox1.ValueMember = "Item_Value";

     }

     privatevoid comboBox1_TextChanged(object sender, EventArgs e)

     {

            ........ Query database . omit .........

            ........According I think. It has some program code for detecting comboitm or deleting comboitm in here. That's my quesion. How to do it?........

            ArrayList comboitm_Kind = newArrayList();

            for (int_Loop = 0; int_Loop < dataset_Result.Tables[0].Rows.Count; int_Loop++)

            {

                  comboitm_Kind.Add(newComboBox_Item(dataset_Result.Tables[0].Rows[int_Loop][2].ToString().ToString(),int.Parse(dataset_Result.Tables[0].Rows[int_Loop][0].ToString())));

            }

            

            comboBox2.DataSource = comboitm_Kind;

            comboBox2.DisplayMember = "ItmText";

            comboBox2.ValueMember = "ItmValue"; 

     }

}

}

publicclassComBoItm

{

     publicstring str_ItmText;

     publicint int_ItmVal;

     public ComBoItm(string str_Text, int int_Val)

     {

            this.str_ItmText = str_Text;

            this.int_ItmVal = int_Val;

     }

     publicstring Item_Text

     {

            get

            {

                  return str_ItmText;

            }

     }

     publicint Item_Value

     {

            get

            {

                  return int_ItmVal;

            }

     }

}


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>