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

Combobox issue.

Hi All,
I am working in VB.NET.
I have a data bound control (combobox) which I want to fill with a certain
field of my table from database ( SQL as backend).
The issue is, I want these values to fill the combo at the index specified
by me, ie, not the usual 0,1,2.... by default. Also, not dataset, but I am
using dataReader.
Can anyone send me the sample code for the same?
Thanks for your help.
Nov 20 '05 #1
3 2109

http://www.devbuzz.com/content/zinc_...center_pg1.asp
"Support" <ab*@pqr.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi All,
I am working in VB.NET.
I have a data bound control (combobox) which I want to fill with a certain
field of my table from database ( SQL as backend).
First off, is this a desktop application or a web application? If it's a
desktop application, then your control won't actually be 'bound' to the
data. The issue is, I want these values to fill the combo at the index specified
by me, ie, not the usual 0,1,2.... by default. Use the .Insert Method as opposed to the Add method to stick them somewhere
other than the beginning. In order to do this, you won't be able to use a
DataTable and the traditional DisplayMember, ValueMember approach, you are
going to have to use the dataReader or at least, if you use a DataTable,
iterate through it using Insert where applicable. Insert takes two
parameters, the index's position where you want it to appear and the item
itself. So, if you wanted to start filling it at index 6
//Doing it with a reader
int i = 6;
while rdr.Read(){
comboBox1.Items.Insert(i, rdr.GetString[0]);
i++;
}
//Doing it with a datatable, note you can't use the traditional
DisplayMember, ValueMember approach.
int i = 6;
foreach(DataRow dro in myDataSet.Tables[TableIndex].Rows){
comboBox1.Iterms.Insert(i, dro[0].ToString());
i++;
}

Also, not dataset, but I am using dataReader.
Good, considering what you are doing, it's the best way. If you don't need
a datatable for exclusive binding reasons and you aren't going to send it
back, you don't need to take the overhead hit associated with a datatable Can anyone send me the sample code for the same? See Above. Let me know if you have any questions
For documentation on Insert vs. add
http://msdn.microsoft.com/library/de...classtopic.asp Thanks for your help.


--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
Nov 20 '05 #2
Hi Support,

When you want a *databound to the SQL backend* you need in my opinion the
Datatable and the dataset.

If you want to use the datareader you can use an Ilist class object however
than it is not databound, just an ordianary object bounded to the combobox.

The index of a combobox start always on -1, which means empty and than 0, 1
etc. to its length.

You can of course build your own class that implements ICollection and with
that search to the index, however that is something totally different.

http://support.microsoft.com/default...b;en-us;306961

I hope I did understand you somehow?

Cor
I am working in VB.NET.
I have a data bound control (combobox) which I want to fill with a certain
field of my table from database ( SQL as backend).
The issue is, I want these values to fill the combo at the index specified
by me, ie, not the usual 0,1,2.... by default. Also, not dataset, but I am
using dataReader.
Can anyone send me the sample code for the same?
Thanks for your help.

Nov 20 '05 #3
Hi Cor and William,
Thanks a ton for taking interest in the problem.
I have got the answer to my questions, through your valued opinion.
Regards.
"William Ryan eMVP" <do********@comcast.nospam.net> wrote in message
news:u$**************@TK2MSFTNGP09.phx.gbl...

http://www.devbuzz.com/content/zinc_...center_pg1.asp
"Support" <ab*@pqr.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi All,
I am working in VB.NET.
I have a data bound control (combobox) which I want to fill with a certain field of my table from database ( SQL as backend).
First off, is this a desktop application or a web application? If it's a
desktop application, then your control won't actually be 'bound' to the
data.
The issue is, I want these values to fill the combo at the index specified by me, ie, not the usual 0,1,2.... by default.

Use the .Insert Method as opposed to the Add method to stick them

somewhere other than the beginning. In order to do this, you won't be able to use a
DataTable and the traditional DisplayMember, ValueMember approach, you are
going to have to use the dataReader or at least, if you use a DataTable,
iterate through it using Insert where applicable. Insert takes two
parameters, the index's position where you want it to appear and the item
itself. So, if you wanted to start filling it at index 6
//Doing it with a reader
int i = 6;
while rdr.Read(){
comboBox1.Items.Insert(i, rdr.GetString[0]);
i++;
}
//Doing it with a datatable, note you can't use the traditional
DisplayMember, ValueMember approach.
int i = 6;
foreach(DataRow dro in myDataSet.Tables[TableIndex].Rows){
comboBox1.Iterms.Insert(i, dro[0].ToString());
i++;
}

Also, not dataset, but I am
using dataReader.
Good, considering what you are doing, it's the best way. If you don't

need a datatable for exclusive binding reasons and you aren't going to send it
back, you don't need to take the overhead hit associated with a datatable
Can anyone send me the sample code for the same?

See Above. Let me know if you have any questions
For documentation on Insert vs. add

http://msdn.microsoft.com/library/de...classtopic.asp
Thanks for your help.


--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/

Nov 20 '05 #4

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

Similar topics

2
by: ross kerr | last post by:
Hi all, I have a control that extends the ComboBox object. It updates the selected item based on what the user enters in the text area. In the OnLeave event of the combobox, the selected...
3
by: Lubomir | last post by:
Hi, I have a combobox and datagrid in a form. When an Item is selected from a combobox, a method is called, which will make selection from a database according selected item and populate...
5
by: malcolm | last post by:
I'm trying to make a combo box custom control (Windows Forms .NET 1.1 c#) that can behave like a label programatically at run time. This is actually a strong feature request by our customers. I...
1
by: pagates | last post by:
Hello All, I seem to have found a problem using a ComboBox. If you bind a ComboBox to an ArrayList of classes, setting the DisplayMember to one field in the class and the ValueMember to...
6
by: Juan Pedro Gonzalez | last post by:
I wanted to add a Combobox to a toolbar... Kind of the look you get on VisualStudio's toolbar. I've been able to find some VB 6 samples, but the placeholder option is no longer available for...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
1
by: amber | last post by:
I'm having an issue with a combobox that is making no sense to me at all. I have a form with several comboboxes/textboxes. The values in these boxes are based on a datarowview, which is based on...
5
by: Rich | last post by:
Hello, I have a search application to search data in tables in a database (3 sql server tables). I populate 2 comboboxes with with data from each table. One combobox will contain unique...
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...
2
by: =?Utf-8?B?V29ua28gdGhlIFNhbmU=?= | last post by:
Hello, I have a ComboBox that has a DataContext set on it. When a PropertyChanged event is fired (based on a static instance of some class), I'd like to update the DataContext on the combo, but...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.