473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

SelectedIndex is not a member of System.Windows.Forms.Control

mshmyob
904 Expert 512MB
I am trying to read values from textbox controls and combobox controls on a form.

Reading the values from textbox controls is working fine but I cannot read from the 3 combo boxes.

Here is some simplified code of what I am trying to do.

Expand|Select|Wrap|Line Numbers
  1. for intCounter = 1 to 3
  2.    dblPrincipal = Me.Controls("txtPrincipal" & intCounter).Text
  3.    intType = Me.Controls("cboM" & intCounter).SelectedIndex
  4. next intCounter
  5.  
The intType= statement (line 3) is where the problem occurs. Error message as in my Question Title. It appears I cannot reference the selectedindex property in the method.

Any ideas how I can do this for 3 combo boxes on my form.

cheers,
Mar 8 '10 #1
5 6973
tlhintoq
3,525 Expert 2GB
Use the .Find method to locate your control. This will return the actual control. If you don't find it, then it doesn't exist. If you do find it, then you have an actual control to work with.

Expand|Select|Wrap|Line Numbers
  1. // C#
  2. combobox Bob = this.controls.find("cbom" + intCount);
  3. if (bob != null)
  4. {
  5.    bob.SelectedIndex;
  6. }
Mar 8 '10 #2
mshmyob
904 Expert 512MB
I need this for vb.net.

The control does exist.

cheers,
Mar 8 '10 #3
mshmyob
904 Expert 512MB
I actually got the controls.find to work but it returns a true/false whether the control exists - This doesn't help me - I know the control exists what I need is to be able to reference the name of the combobox control dynamically without the error.

I do not want to hard code for cboM1, cboM2, cboM3 - I would like it to work like my code for the text boxes above.

cheers,
Mar 8 '10 #4
tlhintoq
3,525 Expert 2GB
SelectedIndex is not a member of System.Windows.Forms.Control
Well.. That would be true.
SelectedIndex is a member of System.Windows.Forms.Controls.ComboBox

Try your original technique but cast your control to a ComboBox instead of a generic 'Control'

Also... Double check all your naming matches letter for letter, case for case, including zeros... I find it suspicious that control.find says you don't have it.

cboM03 is not cboM3 for example
cbom3 is not cboM3
Mar 8 '10 #5
mshmyob
904 Expert 512MB
Try your original technique but cast your control to a ComboBox instead of a generic 'Control'
I am so daft sometimes. I was all around it with declaring controls and comboboxes but it was as simple as the following:

Expand|Select|Wrap|Line Numbers
  1.  
  2. for intCounter = 1 to 3 
  3.    dblPrincipal = Me.Controls("txtPrincipal" & intCounter).Text 
  4.   Dim myComboBox As ComboBox
  5.   myComboBox = Me.Controls("cboM" & intCounter)
  6.   intType = myComboBox.SelectedIndex
  7. next intCounter 
  8.  
  9.  

By the way - control.find always did find it but that was not what I wanted.

Thanks for your guidance.

cheers,
Mar 8 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: swb | last post by:
Hi - I have a simple project that manipulates Adobe Illustrator that works fine at home on Windows XP Pro (with admin login), but gives me an error (error message and source code below) at work...
2
by: Greg Bacchus | last post by:
Hi, I'm getting an exception that really has me stumped. It's sporadic at best, it's only happened a handful of times. This particular time it happened when the user pressed 'Alt-S' to save the...
2
by: ross kerr | last post by:
Hi all, I have a control that extends the ComboBox object. It updates the selected item based on what the user enters in the text area. In the OnLeave event of the combobox, the selected...
6
by: Nathan Sokalski | last post by:
I am writing a User Control that uses 3 DropDownLists. When I attempt to access the SelectedIndex property it incorrectly reports the value selected by the user. Why is this? Here is my code,...
5
by: Eric A. Johnson | last post by:
Hi Everyone, I am at my wit's end here. I have a combobox (combyQueryTitle) that I need to use in order to select a query for my database project. Therefore, I am using the...
4
by: Roger Aikin | last post by:
I've converted a VB6 project to VB.Net 2005. (Actually using vstudio pro 2005). I'm on a machine that also has VB6 and Vstudio.net 2003 on it. The project uses Word, Excel, MapPoint and SqlClient...
3
by: Magnus | last post by:
Im using a set combobox (ComboBox1) to provide a selection of records from a database table. I have a typed dataset (DataSet1) that contains the typed datatable (DataTable1) that the combobox is...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
5
by: Andrus | last post by:
To reproduce, run the code. Observed: System.ArgumentOutOfRangeException was unhandled Message="InvalidArgument=Value of '0' is not valid for 'SelectedIndex'.\r\nParameter name: SelectedIndex"...
0
by: =?Utf-8?B?TWFyY3VzIFNjaGFlZmVy?= | last post by:
Hi everybody, I'm working on my application for appr. 2 years and now suddenly I got an System.TypeInitializationException in one of my global modules. The error is thrown at the first call of a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.