Creating controls at runtime



Hello Everyone:

I am new to C# and trying to create controls at runtime.

I create two listbox at run time and load the values to first one.
I disable the second listbox at time of creation[at runtime].

My requirement is when i change the first listbox value i want the
second listbox to enable and load the values .

E.g first listbox has all the countries and when i change the country i
want the second one to fille the provinces/states.

Below are the code to load the first listbox.
ListBox oObjCMB = new ListBox();
string iID = oDr.GetInt32(7).ToString().Trim();
string sSQL2 = "select * from holder where id = " + iID ;
SqlCommand oCmd3 = new SqlCommand(sSQL2,oCn2);
sqlDataReader oDr3 = oCmd3.ExecuteReader();
while(oDr3.Read())
{
oObjCMB.Items.Add(oDr3.GetValue(2).ToString().Trim());
}
TableRow tr = new TableRow();
TableCell td1 = new TableCell();
oObjCMB.ID = oDr.GetString(3);
td1.Controls.Add(oObjCMB);

Same way i create the empty listbox and disable it add to table.

Can some Please tell me how i can implement the
oObjCMB.SelectedIndexChanged

Thanks in Advance.

Pargat

.



Relevant Pages

  • Re: MVP please help - ShowDialog() very slow
    ... You need to remember that the ListBox control is a wrapper around the old ... This is why the display phase is so time-consuming. ... quickly and continue to load while the user is doing other things. ... >when the list box switches to visible as part of ShowDialog(). ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Extract fields from a database dependant on a user inputted ke
    ... Then to load a ListBox on the userform with data from and Access table, ... Dim rs As DAO.Recordset ... ' Load the ListBox with the retrieved records ...
    (microsoft.public.word.vba.general)
  • Re: MVP please help - ShowDialog() very slow
    ... You should also consider using asynchronous delegates to load your data. ... can either disable the listbox while the data is loading or show some kind ... > You need to remember that the ListBox control is a wrapper around the old ... >>when the list box switches to visible as part of ShowDialog(). ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: .net cf listbox / combobox
    ... replaced them with a clickable label and an image control that make it look ... a listbox and a find button. ... really a clickable label control. ... This mechanism seems to work fine thus making the initial load time ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: .net cf listbox / combobox
    ... scroll to the bottom of the listbox, and in doing so loads all the data, ... > load into the ListBox and I was able to display them all so I did not find ... > into the ListBox and each time the user taps on the vertical scroll bar, ... >> understand the design consideration that both of you mention, ...
    (microsoft.public.dotnet.framework.compactframework)

Loading