Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 25th, 2004, 07:44 AM
Registered User
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Checking a ComboBox

I have a ComboBox on a Form in an application. In this ComboBox i want the users to either choose one of the items in the list or enter a new item. When the user is finished filling out all required fields, i need to check:
1) If some new text has been written in the ComboBox
2) If the user has selected a new item after writing in the ComboBox
3) If the text written is the same as one of the other items in the list.
I am struggeling to work out wich controls to use for this purpose, any help will be greatly appreciated.
Old November 25th, 2004, 08:37 AM
Registered User
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts

Ok, i've encountered some new problems :)

When the form is shown, the following line of code is executed:
cbx_type.DataSource = prog.HentTyper();
cbx_type is the ComboBox in question, and the "prog.HentTyper()" method returns an array of strings. This works fine, but now there doesnt seem to be an editable field in the ComboBox. It is possible to erase one of the existing choices and enter new text but whenever someone enters any text (and selects this text when submitting) the following if-test will execute:

if(cbx_type.SelectedText.Length < 1)
This tells me that there is something wrong somewhere :) Anybody care to explain?
Old November 30th, 2004, 05:49 PM
Kep Kep is offline
Authorized User
Join Date: Aug 2003
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts

You could try...
if(cbx_type.Text.Length < 1)
The help isn't entirely clear about the difference between SelectedText and Text, but I thought the text of a ComboBox was returned by Text.

What is the DropDownStyle of your ComboBox?


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filling Combobox with value from other Combobox ayazhoda Access VBA 6 June 5th, 2007 04:58 AM
Checking for Duplicates timeware ASP.NET 2.0 Professional 2 July 20th, 2006 08:41 AM
checking first sibling stavinoha XSLT 2 July 4th, 2006 02:13 AM
Checking for duplicates toedipper2 SQL Server 2000 3 June 7th, 2006 03:50 PM
Checking for a number aware Classic ASP Basics 5 June 5th, 2003 09:57 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.