|
|
|
date: Tue, 1 Jul 2008 08:19:01 -0700,
group: microsoft.public.dotnet.framework.windowsforms.controls
back
RE: Combobox Data
Thanks for the info... thinking about what you said about not wanting to load
a future comobox with all of the data the other ones are getting... so I
decided to tag all the comboboxes with the word "CliveList" to the Combobox
name and then I added an "if" statement to check if the phrase is in the the
name and if it is it loads the list..... all works well...
Dim sColList As New List(Of String)()
GetExcelData.ReadExcelFile("Clive", DS)
For Each column As DataColumn In DS.Tables(0).Columns
sColList.Add(column.ColumnName)
Next
For Each control As Control In Me.TabPage1.Controls
If TypeOf control Is ComboBox Then
If InStr(control.Name, "CliveList") Then
CType(control,
ComboBox).Items.AddRange(sColList.ToArray())
End If
End If
Next
Thanks for help...
dotnetme
"Morten Wennevik [C# MVP]" wrote:
>
> "dotnetme" wrote:
>
> > Basically i read in an excel sheet into a untype(simple) Dataset and then i
> > what to load all the Column names of the dataset into the item list of the
> > comboboxes... Well i want to do this the most efficent way and not sure how
> > to... I can definitly do it by calling each combobox and load the info in
> > but i don't want to hard code that... incase i change the number of Combo
> > boxes.. so should i loop through the form and add all comboboxes to a list
> > then loop through that list and then set the item list???
> >
>
> You could loop through all the Controls in a TabPage and set the Items
> property, but the code wouldn't work if you later decide to put the
> ComboBoxes inside a GroupBox on that TabPage, or any other container control.
> You could recursively loop through all controls on the form and set all
> ComboBoxes no matter where they were located, but that would prevent you from
> using a ComboBox with a separate list of Items. Your best bet is to keep a
> reference to all the necessary ComboBoxes in a separate list, or add a line
> of code for each ComboBox where you set the Items property (this is probably
> the easiest to understand if someone else reads your code).
>
> If you prefer the 'loop through tabpage1' option, the code below would
> probably be the most efficient way.
>
> Dim sColList As New List(Of String)()
>
> GetExcelData.ReadExcelFile("Clive", DS)
>
> For Each column As DataColumn In DS.Tables(0).Columns
> sColList.Add(column.ColumnName)
> Next
>
> For Each control As Control In Me.TabControl1.Controls
> If TypeOf control Is ComboBox Then
> CType(control, ComboBox).Items.AddRange(sColList.ToArray())
> End If
> Next
>
> --
> Happy Coding!
> Morten Wennevik [C# MVP]
>
>
>
date: Thu, 3 Jul 2008 07:07:01 -0700
author: dotnetme
|
|