Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > combo box question


Reply
 
Thread Tools Display Modes
  #1  
Old 11-10-2006, 11:48 AM
ADO DOT NET ADO DOT NET is offline
Junior Contributor
 
Join Date: May 2006
Posts: 209
Default combo box question


I use this code to get a file name from user and add it to a combo box"
Code:
If OpenFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then Dim Counter As Integer For Counter = 1 To OpenFileDialog.FileNames.Length FileComboBox.Items.Add(OpenFileDialog.FileNames(Counter - 1).ToString) Next End If
My problem is that if user select a file twice it will be added, since it shouldn't be added! How to prevent the combo box from getting duplicated file names?
Reply With Quote
  #2  
Old 11-10-2006, 12:28 PM
wayneph's Avatar
wayneph wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

You add code to check your ComboBox Items.

How much programming have you done? This is a simple Loop with an If statement. If you don't get this part, you're going to have a miserable career.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #3  
Old 11-10-2006, 01:21 PM
stevo stevo is offline
Senior Contributor

* Expert *
 
Join Date: May 2004
Location: Manchester, England.
Posts: 1,254
Default

Before adding to the combobox use the FindStringExact property of the combobox and if it returns -1 then you can add to it
Code:
If FileComboBox.FindStringExact(OpenFileDialog.FileNames(Counter - 1).ToString) = -1 Then FileComboBox.Items.Add(OpenFileDialog.FileNames(Counter - 1).ToString) End If
Reply With Quote
  #4  
Old 11-12-2006, 05:26 AM
ADO DOT NET ADO DOT NET is offline
Junior Contributor
 
Join Date: May 2006
Posts: 209
Default

Quote:
Originally Posted by wayneph
You add code to check your ComboBox Items.

How much programming have you done? This is a simple Loop with an If statement. If you don't get this part, you're going to have a miserable career.
dear sir
i am sorry for posting such question. in the future i think more about my posts! for now it seems that you are having a great career in programming. so could you be so kind and help me with this:
http://www.xtremevbtalk.com/showthread.php?t=274316
???
thanks
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->