problem with combobox in tabcontrol
-
hello every one i m having '11' tabpages in tabcontrol now in each page there are 11 combobox i named them starting from '0' like cmb0 which is in 1st tabpage,cmb1 which is in second tabpage and like wise... now all 11 comboboxes have same items in it and i want to insert all of them using loop for that i had code is like
dim i as integer
cmbstr as combobox
For i = 0 To 11cmbstr = cmbstr & i cmbstr.Items.add("a") cmbstr.Items.add("b") cmbstr.Items.add("c") cmbstr.Items.add("d") Next i = i + 1
but this shows some error please help.. please suggest if some another alternative is possible.. :) :) :)
-
hello every one i m having '11' tabpages in tabcontrol now in each page there are 11 combobox i named them starting from '0' like cmb0 which is in 1st tabpage,cmb1 which is in second tabpage and like wise... now all 11 comboboxes have same items in it and i want to insert all of them using loop for that i had code is like
dim i as integer
cmbstr as combobox
For i = 0 To 11cmbstr = cmbstr & i cmbstr.Items.add("a") cmbstr.Items.add("b") cmbstr.Items.add("c") cmbstr.Items.add("d") Next i = i + 1
but this shows some error please help.. please suggest if some another alternative is possible.. :) :) :)
nazimghori wrote:
but this shows some error
And that error would be ....... ??? Do you really think that there's only a single error possible when dealing with a combobox??
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
nazimghori wrote:
but this shows some error
And that error would be ....... ??? Do you really think that there's only a single error possible when dealing with a combobox??
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Let me do a mind meld with the computer (just seen the new Star Trek move) uhm, uhm, oh bugger that's the monitor you idiot now you've got indentations on the flat screen!
Never underestimate the power of human stupidity RAH
-
nazimghori wrote:
but this shows some error
And that error would be ....... ??? Do you really think that there's only a single error possible when dealing with a combobox??
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008hi error is like operator '&' is not not defined for type 'system.windows.form.comboox' and integer seems to be syntax error but please suggest how to solve it... thank you in advance... :) :)
-
hello every one i m having '11' tabpages in tabcontrol now in each page there are 11 combobox i named them starting from '0' like cmb0 which is in 1st tabpage,cmb1 which is in second tabpage and like wise... now all 11 comboboxes have same items in it and i want to insert all of them using loop for that i had code is like
dim i as integer
cmbstr as combobox
For i = 0 To 11cmbstr = cmbstr & i cmbstr.Items.add("a") cmbstr.Items.add("b") cmbstr.Items.add("c") cmbstr.Items.add("d") Next i = i + 1
but this shows some error please help.. please suggest if some another alternative is possible.. :) :) :)
There are several approaches possible: 1. create a ComboBox array or collection (a generic list), copy a reference to each of the comboboxes in the list once (say in your form load handler), then do a foreach over that array every time you need to. 2. assuming there is only the one combobox on every tab page, execute the following pseudocode:
foreach tabpage in tabcontrol
foreach control in tabpage
if control is combobox (skipping the other controls, e.g. buttons)
do what needs to be done:)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
modified on Sunday, May 10, 2009 8:03 AM
-
There are several approaches possible: 1. create a ComboBox array or collection (a generic list), copy a reference to each of the comboboxes in the list once (say in your form load handler), then do a foreach over that array every time you need to. 2. assuming there is only the one combobox on every tab page, execute the following pseudocode:
foreach tabpage in tabcontrol
foreach control in tabpage
if control is combobox (skipping the other controls, e.g. buttons)
do what needs to be done:)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
modified on Sunday, May 10, 2009 8:03 AM
hello i knew this approach but there are more than one combobox on each tabpage... so please suggest some other approach... :) :) :)
-
hello i knew this approach but there are more than one combobox on each tabpage... so please suggest some other approach... :) :) :)
I gave you two solutions, the first works no matter what. the second can be modified to cope with multiple comboboxes per tabpage: give the ones you want a special characteristic (e.g. through their Name, their Location or their Tag) and test inside the "foreach control" loop. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
hi error is like operator '&' is not not defined for type 'system.windows.form.comboox' and integer seems to be syntax error but please suggest how to solve it... thank you in advance... :) :)
Of course not. You're trying to build the name of a ComboBox in a string and then treating that string as if it was the combobox. That's not going to work. Luc has the best two solutions for you.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008modified on Sunday, May 10, 2009 9:46 PM
-
I gave you two solutions, the first works no matter what. the second can be modified to cope with multiple comboboxes per tabpage: give the ones you want a special characteristic (e.g. through their Name, their Location or their Tag) and test inside the "foreach control" loop. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
hello i tried the second approach i gave the tag values of each combobox in tabpage to '0' at design time..
Sub fill(ByVal tbcon As TabControl)
Dim cnt As Control For Each cnt In tbcon.Controls If TypeOf cnt Is ComboBox Then Select Case Tag Case 0 cnt.Items.Add("NP") cnt.Items.Add("ND") cnt.Items.Add("FP") cnt.Items.Add("FD") End Select End If Next End Sub
but this shows the syntax error like 'item is no the member of 'system.windows.forms.controls' please help....
-
I gave you two solutions, the first works no matter what. the second can be modified to cope with multiple comboboxes per tabpage: give the ones you want a special characteristic (e.g. through their Name, their Location or their Tag) and test inside the "foreach control" loop. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
hello i tried another alternative like
dim cmbcntrl as combobox
Dim combos() As String = New String() {"NP", "ND", "FP", "FD"}
dim i as string
For i = 0 To 11
cmbcntrl = cmbcntrl.Items.AddRange(combos)
nextthere are 11 comboxes and 11 tabpage each tabpage having 1 combobox now i name these comboboxes like combobox0,combobox1,combobox3.....and also there are other comboboxes in tabpages but they are with different name.. and tried above loop but still theres an error like:- 'expression doesnot produce a value..' so please suggest what shall i do.. thank you.... :) :) :)
-
I gave you two solutions, the first works no matter what. the second can be modified to cope with multiple comboboxes per tabpage: give the ones you want a special characteristic (e.g. through their Name, their Location or their Tag) and test inside the "foreach control" loop. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
hello i tried other approach like
Dim combos() As String = New String() {"NP", "ND", "FP", "FD"}
Dim i As Integer
dim cmbcntrl as combobox
For i = 0 To 11
cmbcntrl = cmbcntrl.Items.AddRange(combos)i am having 11 comboboxes and 11 tabpages each having one combobox now i name these comboboxes like :combobox0,combobox1,combobox3....upto '11' and also there are other comboboxes in some tabpages but they are with different name.... now i tried above loop but it still states the syntax error like 'expression doesnot produces a value...' so please suggest what shall i do to solve it.. thank you.... :) :)
-
hello i tried other approach like
Dim combos() As String = New String() {"NP", "ND", "FP", "FD"}
Dim i As Integer
dim cmbcntrl as combobox
For i = 0 To 11
cmbcntrl = cmbcntrl.Items.AddRange(combos)i am having 11 comboboxes and 11 tabpages each having one combobox now i name these comboboxes like :combobox0,combobox1,combobox3....upto '11' and also there are other comboboxes in some tabpages but they are with different name.... now i tried above loop but it still states the syntax error like 'expression doesnot produces a value...' so please suggest what shall i do to solve it.. thank you.... :) :)
Dim arr() As String = {"NP","ND","FP","FD",...}
For Each tabPage In TabControl1
For Each control In TabPage
If control Is ComboBox Then
control.Items.AddRange(arr)
End If
Next
NextSurely this works
I don't speak Idiot - please talk slowly and clearly I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury Driven to the arms of Heineken by the wife
-
Dim arr() As String = {"NP","ND","FP","FD",...}
For Each tabPage In TabControl1
For Each control In TabPage
If control Is ComboBox Then
control.Items.AddRange(arr)
End If
Next
NextSurely this works
I don't speak Idiot - please talk slowly and clearly I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury Driven to the arms of Heineken by the wife
hello the code suggested had an syntax error like 'tabpage is a type and cannot be used as an expression' so please suggest what shall i do to solve it.... :) :)
-
hello i tried the second approach i gave the tag values of each combobox in tabpage to '0' at design time..
Sub fill(ByVal tbcon As TabControl)
Dim cnt As Control For Each cnt In tbcon.Controls If TypeOf cnt Is ComboBox Then Select Case Tag Case 0 cnt.Items.Add("NP") cnt.Items.Add("ND") cnt.Items.Add("FP") cnt.Items.Add("FD") End Select End If Next End Sub
but this shows the syntax error like 'item is no the member of 'system.windows.forms.controls' please help....
Of course your code does not compile: cnt is declared a Control, and Control does not have an Items property. You need to cast it to a ComboBox, something like
Dim combo as ComboBox=DirectCast(cnt, ComboBox)
:)Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
hello i tried the second approach i gave the tag values of each combobox in tabpage to '0' at design time..
Sub fill(ByVal tbcon As TabControl)
Dim cnt As Control For Each cnt In tbcon.Controls If TypeOf cnt Is ComboBox Then Select Case Tag Case 0 cnt.Items.Add("NP") cnt.Items.Add("ND") cnt.Items.Add("FP") cnt.Items.Add("FD") End Select End If Next End Sub
but this shows the syntax error like 'item is no the member of 'system.windows.forms.controls' please help....
..it should read somthiing like:
Sub fill(ByVal tbcon As TabControl) Dim cnt As Control For Each cnt In tbcon.Controls If TypeOf cnt Is ComboBox Then Select Case **CType(cnt, ComboBox).Tag** Case 0 cnt.Items.Add("NP") cnt.Items.Add("ND") cnt.Items.Add("FP") cnt.Items.Add("FD") End Select End If Next End Sub
Otherways the compiler doesn't know 'Tag' Regards: Didi