473,224 Members | 1,572 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,224 software developers and data experts.

ComboBox Items

I am trying to populate a combobox with a lisy of items. I want the 1st item
to be "Make a Selection" and the following items will be names from a table
in my DB (See code below).

When I run the project, the combox box initially displays an empty
selection. When I click on the drop down arrow I see the "Make a Selection"
followed by the other choices.

How can I move everything up so that the "Make a Selection" is the default
value in the combo box?

Wayne

============= code ================
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=c:\Program Files\MyApp\MyData.mdb")

strSQL = "SELECT Name FROM Table1 WHERE (EQ = Yes) Order By Name"

cn.Open() 'Open the connection

Dim cmd As New OleDbCommand(strSQL, cn)

Dim rdr As OleDbDataReader = cmd.ExecuteReader

cboSample.Items.Clear()

cboSample.Items.Add("Make a Selection")

While (rdr.Read())

cboSample.Items.Add(rdr.GetString(0)) ' Name is the only field returned

End While

rdr.Close()
--
------------------------------------
Wayne Wengert
wa***@wengert.org
Jul 19 '05 #1
3 7439

Hi Wayne,

The item the combobox initially displays should be set by the combobox's
text property.

Hope this helps.

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Wayne Wengert" <wa***@wengert.org>
| Subject: ComboBox Items
| Date: Tue, 5 Aug 2003 15:49:31 -0600
| Lines: 44
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <uR**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.general
| NNTP-Posting-Host: skybeam143.skybeam.frii.net 216.17.229.143
| Path:
cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA05.phx.gbl!TK2MSFTNGP08
phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:103592
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| I am trying to populate a combobox with a lisy of items. I want the 1st
item
| to be "Make a Selection" and the following items will be names from a
table
| in my DB (See code below).
|
| When I run the project, the combox box initially displays an empty
| selection. When I click on the drop down arrow I see the "Make a
Selection"
| followed by the other choices.
|
| How can I move everything up so that the "Make a Selection" is the default
| value in the combo box?
|
| Wayne
|
| ============= code ================
| Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
| Source=c:\Program Files\MyApp\MyData.mdb")
|
| strSQL = "SELECT Name FROM Table1 WHERE (EQ = Yes) Order By Name"
|
| cn.Open() 'Open the connection
|
| Dim cmd As New OleDbCommand(strSQL, cn)
|
| Dim rdr As OleDbDataReader = cmd.ExecuteReader
|
| cboSample.Items.Clear()
|
| cboSample.Items.Add("Make a Selection")
|
| While (rdr.Read())
|
| cboSample.Items.Add(rdr.GetString(0)) ' Name is the only field returned
|
| End While
|
| rdr.Close()
|
|
| --
| ------------------------------------
| Wayne Wengert
| wa***@wengert.org
|
|
|

Jul 19 '05 #2
I gather this does not apply when you bind the combobox to a dataset? The
1st item in the dataset shows in the text?

Wayne

"Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
news:8V****************@cpmsftngxa06.phx.gbl...

Hi Wayne,

The item the combobox initially displays should be set by the combobox's
text property.

Hope this helps.

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Wayne Wengert" <wa***@wengert.org>
| Subject: ComboBox Items
| Date: Tue, 5 Aug 2003 15:49:31 -0600
| Lines: 44
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <uR**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.general
| NNTP-Posting-Host: skybeam143.skybeam.frii.net 216.17.229.143
| Path:
cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA05.phx.gbl!TK2MSFTNGP08 phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:103592
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| I am trying to populate a combobox with a lisy of items. I want the 1st
item
| to be "Make a Selection" and the following items will be names from a
table
| in my DB (See code below).
|
| When I run the project, the combox box initially displays an empty
| selection. When I click on the drop down arrow I see the "Make a
Selection"
| followed by the other choices.
|
| How can I move everything up so that the "Make a Selection" is the default | value in the combo box?
|
| Wayne
|
| ============= code ================
| Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
| Source=c:\Program Files\MyApp\MyData.mdb")
|
| strSQL = "SELECT Name FROM Table1 WHERE (EQ = Yes) Order By Name"
|
| cn.Open() 'Open the connection
|
| Dim cmd As New OleDbCommand(strSQL, cn)
|
| Dim rdr As OleDbDataReader = cmd.ExecuteReader
|
| cboSample.Items.Clear()
|
| cboSample.Items.Add("Make a Selection")
|
| While (rdr.Read())
|
| cboSample.Items.Add(rdr.GetString(0)) ' Name is the only field returned
|
| End While
|
| rdr.Close()
|
|
| --
| ------------------------------------
| Wayne Wengert
| wa***@wengert.org
|
|
|

Jul 19 '05 #3

Hi Wayne,

I do not quite understand your meanning, but I think you can do like this:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data .SqlClient;

namespace testcombobox
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox comboBox1;
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code

private void InitializeComponent()
{
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(64, 152);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(152, 21);
this.comboBox1.TabIndex = 0;
this.comboBox1.Text = "comboBox1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
SqlDataAdapter adapter=new SqlDataAdapter ("select * from titles where
price!=0","server=localhost;database=pubs;uid=sa;p wd=");

DataSet ds=new DataSet ();
adapter.Fill (ds);
comboBox1.Text ="Please select a item";
comboBox1.Items.Clear ();
foreach(DataRow row in ds.Tables [0].Rows)
{
comboBox1.Items .Add (row.ItemArray [0]);
}
}
}
}

I use sqlserver to add data to comboBox and it works well on my machine.

Hope it helps

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Wayne Wengert" <wa***@wengert.org>
| References: <uR**************@TK2MSFTNGP12.phx.gbl>
<8V**************@cpmsftngxa06.phx.gbl>
| Subject: Re: ComboBox Items
| Date: Wed, 6 Aug 2003 05:01:45 -0600
| Lines: 91
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <eM**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.general
| NNTP-Posting-Host: skybeam143.skybeam.frii.net 216.17.229.143
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:103674
| X-Tomcat-NG: microsoft.public.dotnet.general
|
| I gather this does not apply when you bind the combobox to a dataset? The
| 1st item in the dataset shows in the text?
|
| Wayne
|
| "Jeffrey Tan[MSFT]" <v-*****@online.microsoft.com> wrote in message
| news:8V****************@cpmsftngxa06.phx.gbl...
| >
| > Hi Wayne,
| >
| > The item the combobox initially displays should be set by the combobox's
| > text property.
| >
| > Hope this helps.
| >
| > Jeffrey Tan
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| > This posting is provided "as is" with no warranties and confers no
rights.
| >
| > --------------------
| > | From: "Wayne Wengert" <wa***@wengert.org>
| > | Subject: ComboBox Items
| > | Date: Tue, 5 Aug 2003 15:49:31 -0600
| > | Lines: 44
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <uR**************@TK2MSFTNGP12.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.general
| > | NNTP-Posting-Host: skybeam143.skybeam.frii.net 216.17.229.143
| > | Path:
| >
|
cpmsftngxa06.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA05.phx.gbl!TK2MSFTNGP08
| > phx.gbl!TK2MSFTNGP12.phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:103592
| > | X-Tomcat-NG: microsoft.public.dotnet.general
| > |
| > | I am trying to populate a combobox with a lisy of items. I want the
1st
| > item
| > | to be "Make a Selection" and the following items will be names from a
| > table
| > | in my DB (See code below).
| > |
| > | When I run the project, the combox box initially displays an empty
| > | selection. When I click on the drop down arrow I see the "Make a
| > Selection"
| > | followed by the other choices.
| > |
| > | How can I move everything up so that the "Make a Selection" is the
| default
| > | value in the combo box?
| > |
| > | Wayne
| > |
| > | ============= code ================
| > | Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
| > | Source=c:\Program Files\MyApp\MyData.mdb")
| > |
| > | strSQL = "SELECT Name FROM Table1 WHERE (EQ = Yes) Order By Name"
| > |
| > | cn.Open() 'Open the connection
| > |
| > | Dim cmd As New OleDbCommand(strSQL, cn)
| > |
| > | Dim rdr As OleDbDataReader = cmd.ExecuteReader
| > |
| > | cboSample.Items.Clear()
| > |
| > | cboSample.Items.Add("Make a Selection")
| > |
| > | While (rdr.Read())
| > |
| > | cboSample.Items.Add(rdr.GetString(0)) ' Name is the only field
returned
| > |
| > | End While
| > |
| > | rdr.Close()
| > |
| > |
| > | --
| > | ------------------------------------
| > | Wayne Wengert
| > | wa***@wengert.org
| > |
| > |
| > |
| >
|
|
|

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rachel Suddeth | last post by:
When I put a ComboBox on a form, I can enter strings through the designer to fill Items collections. I have put a ComboBox in a UserControl, and exposed the the Items collections with the same...
5
by: James P. | last post by:
Hello, For my new Windows application, all I want is to create an initial form to demo to the user to show them how it looks like with some data on it. So I figure the fastest way is to create...
6
by: Sakharam Phapale | last post by:
Hi All, How to fill one ComboBox from other ComboBox control? 1) Only setting the reference does the trick but doesn't show items in control. If you see in immediate window, it shows...
3
by: Wayne Wengert | last post by:
I am trying to populate a combobox with a lisy of items. I want the 1st item to be "Make a Selection" and the following items will be names from a table in my DB (See code below). When I run the...
8
by: | last post by:
I am sure this has been asked and answered, but here goes anyway... VS.Net 2005, VB.Net How can you display more than one field in the displaymember property of a combobox inside the...
7
by: samoore33 | last post by:
I am trying to dynamically add items to a listbox or combobox. The items add to either, but when I look through those items, there is nothing there. If I choose an item, it shows up. Not sure...
5
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I want to create a customized ComboBox where the methods ComboBox.Items.Add and ComboBox.Items.Insert will behave thusly: -- If the item is not present, add it. -- If the item is present, set the...
4
by: Jerad Rose | last post by:
I'm baffled by this -- is there not a typed object used for ComboBox Items? Best I can tell, all of the methods for ComboBox that accept an Item are of type Object. Why in the world is a...
5
by: Kevinp | last post by:
I've spent the last four hours Google searching for a way to disable items in a Combobox. I found one example in C++ which I can't get to work and another in C# that I couldn't get to work either....
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.