Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To 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 August 19th, 2004, 01:28 AM
Registered User
 
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default default selection in a datacombo

Hi i need some help on working with a datacombo..

what i am trying to do is set a default selection in a datacombo. i.e. if my datacombo is bound to a column containing id's like 1,2,3 then i want that id 3 should come as selected by default.

any help on this will be appreciated
 
Old August 19th, 2004, 06:55 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

If you look at the form in design view and look at your combobox's property window, you can set a default value there.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old August 21st, 2004, 12:00 AM
Registered User
 
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi
Thanx for replying to my posting

But actually i was looking for a way for dynamically setting the default selection in a datacombo. Found a solution for it. It can be done as follows:

After populating the datacombo, set
datacomboNAME.Text = strDescription

where strDescription is the description field corresponding to the id that we wish to select by default

Thanx anyway
 
Old August 23rd, 2004, 07:04 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

No, that's not how you set a default in code. What you did was to actually assign the textbox a value. It just so happens the value is strDescription.

To set a default with code it's

Me.datacomboNAME.DefaultValue = strDescription

What's the difference?

If you use the .DefaultValue method like I did, then:

You're on the last record, say number 10.
You scroll forward to add a new record.
You start typing in a field.
Your new record, number 11, is created.
Your datacombo gets the default automatically.

OR

You're on the last record, say no. 10.
You scroll forward to add a new record.
You change your mind and scroll back.
Your new record, would have been no. 11, is NOT created.
You still have only 10 records.

If you do it your way.

You're on the last record, say number 10.
You scroll forward to add a new record.
Your datacombo has no default. You literally assign it a value.
You start typing in another field.
Your new record, number 11, is created.

OR

You're on the last record, say no. 10.
You scroll forward to add a new record.
Your datacombo has no default. You literally assign it a value.
You change your mind and scroll back.
Your new record, no. 11, is STILL created, but it only has one field filled out, i.e. the datacombo.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old August 24th, 2004, 11:53 PM
Registered User
 
Join Date: Aug 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Thanx for explaining it to me. But I was not able to find the 'defaultValue' property !!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding Dataset to DataCombo in .NET TokenBug ADO.NET 4 September 29th, 2006 05:02 AM
Sending a message to a DataCombo Box control vikramrj Pro VB 6 0 June 3rd, 2006 12:47 PM
Set Default selection in ListBox nmreid Classic ASP Basics 0 January 20th, 2006 04:49 PM
About the Datacombo momowu0701 VB.NET 2002/2003 Basics 0 November 25th, 2004 10:56 PM
Problem of the datacombo momowu0701 VB How-To 0 March 14th, 2004 11:58 PM





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