473,698 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2121

http://www.devbuzz.com/content/zinc_...center_pg1.asp
"Support" <ab*@pqr.com> wrote in message
news:%2******** ********@tk2msf tngp13.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.Table s[TableIndex].Rows){
comboBox1.Iterm s.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********@com cast.nospam.net > wrote in message
news:u$******** ******@TK2MSFTN GP09.phx.gbl...

http://www.devbuzz.com/content/zinc_...center_pg1.asp
"Support" <ab*@pqr.com> wrote in message
news:%2******** ********@tk2msf tngp13.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.Table s[TableIndex].Rows){
comboBox1.Iterm s.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
4526
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 index is set to the proper item. However, when accessing its selectedindex later it has reverted to the previous value. The selectedindex value is always one behind what
3
3271
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 datagrid. I used comboBoxLastName_SelectedValueChanged handler, but this handler is called for every Item when combobox is initialized at the start. It means there is made database access for every item, which is not needed and slows down application.
5
4309
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 really don't want to have to make a UserControl that has both a label and ComboBox in it. I would rather have my control derive from a ComboBox for databinding (and other) reasons. I can get close, I've tried setting cbo.DropDownStyle =...
1
1411
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 another, and the ComboBox is sorted, then the bounded indices are incorrect. It appears that the ComboBox is sorted on ValueMember, but the associated DisplayMember does not come along for the ride.
6
3123
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 ToolbarButtons... Does anyone know how this could be done? Looking forward to hear from you,
4
4615
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 bound to a table as a lookup, drawing values from another table to populate the available selections. This all worked fine in VB6. I have distilled the problem down to a simple form drawing data from the Northwind database for a representative...
1
2067
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 a listbox.selecteditem. When a different item is selected in the listbox, all the fields are repopulated with the correct data. I have 1 combobox which is acting weird.
5
5906
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 CompanyID's. The second combobox will contain unique memberID's. Each of the tables that I have to search contain a CompanyID and a memberID field, and these fields are not unique in the respective tables. Like CompanyID, MemberID
4
6663
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 common/standard .NET control accepting an Object as a parameter type? In Web Forms, there is a ListItem object that can be passed in to add/retrieve objects from a DropDownItems collection. I searched Google groups, and all the solutions I'm finding...
2
9794
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 it seems that I need to set it to null first: Combo1.DataContext = null; Combo1.DataContext = dc;
0
8675
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8862
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7729
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.