PC Review


Reply
Thread Tools Rate Thread

ComboBox add item problem

 
 
=?Utf-8?B?S2VudA==?=
Guest
Posts: n/a
 
      16th Aug 2005
Hi,

I would like to populate some data (4 records) to a ComboBox from Datatable
with an empty row as first row.
Here is what I did...
\\\
Dim dr as datarow

dr = Datatable1.NewRow
dr("ColumnName1") = ""
dr("ColumnName2") = ""
ComboBox1.Items.Add(dr)
For Each dr In Datatable1.rows
ComboBox1.Items.Add(dr)
Next
ComboBox1.ValueMember = "ColumnName1"
ComboBox1.DisplayMember = "ColumnName2"
///

However, when I run it, I only got 5 row of "System.Data.DataRow"
I did exactly the same thing on the other form before but it worked.
Am I missing something?

Please help and thanks in advance.
 
Reply With Quote
 
 
 
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      16th Aug 2005
Kent,

A combobox combines the possibilitiy of a itemcollection and a datasource.
They both are in the combobox.

Probably you can try this,

> Dim dr as datarow
> dr = Datatable1.NewRow
> dr("ColumnName1") = ""
> dr("ColumnName2") = ""


DataTable.Rows.Add(dr)
datatable1.defaultview.sort = "ColumnName1"
Combobox1.datasource = datatable1.defaultview ' the last is default
> ComboBox1.ValueMember = "ColumnName1"
> ComboBox1.DisplayMember = "ColumnName2"


I hope this helps,

Cor


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How to select the first combobox item (ie. Set Combobox.ListIndex = 0) Dirk Goldgar Microsoft Access Form Coding 0 11th Aug 2009 03:10 PM
add item to comboBox =?Utf-8?B?bWFydGluMQ==?= Microsoft VB .NET 4 16th Nov 2007 04:37 PM
Re: How to display the first Item in a combobox as the default item Nigel Microsoft Excel Programming 2 8th Dec 2006 10:21 PM
Re: How to display the first Item in a combobox as the default item Jim Cone Microsoft Excel Programming 0 8th Dec 2006 06:42 PM
last item in combobox Graeme Microsoft Dot NET Framework Forms 3 23rd Feb 2004 06:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:39 AM.