473,593 Members | 2,907 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combo box load from a table

Dear NG,

I have successfully bound a combo box to a table when only one column was
involved. I am trying to present the user with the primary key to an
item-location table. The primary key involves two columns, loc_PartNo and
loc_location. My method: GetItemLocListi ng() works fine and returns the
DataTable that I instantiate to locTable. I can not get the combo box to
display and select both parts of the Primary Key. To test the combo box I
have established three examples of Primary Keys in the ArrayList: locations.
For ease of parsing, I have inserted the pipe character ("|") between the
two columns. This works fine. I can think of a number of ways to approach
this problem, but so far nothing has worked due to my limited knowledge of
C#, SQL, and ADO.NET. Here are my thoughts:

1/ Get the data directly out of the DataTable. I would need to "explain" to
the .ValueMember where each part of the Primary Key is such that it displays
both parts.

2/ Some how assign the ArrayList to the concatenated columns of the Primary
Key. In an ideal world this would be done indirectly by over-laying the
ArrayList on top of the DataTable.

3/ Although it would be inefficient, copy each row of the DataTable into the
ArrayList.

Any and all suggestions would be appreciated,

Bob

Robert Schuldenfrei
bo*@s-i-inc.com

private void frmFindLoc_Load (object sender, System.EventArg s e)

{

BindComboBox();

//Make sure Tag property is set even if no scrolling is done.

this.Tag = cboItemLoc.Sele ctedValue;

}

public static DataTable GetItemLocList( )

{

SqlConnection mcs3Connection = MCS3_DB.GetConn ection();

string selectStmt = "SELECT loc_PartNo, loc_location FROM ItemLoc ORDER BY "

+ "loc_PartNo , loc_location";

SqlCommand selectCommand = new SqlCommand(sele ctStmt, mcs3Connection) ;

mcs3Connection. Open();

SqlDataAdapter locDataAdapter = new SqlDataAdapter( selectCommand);

DataSet locDataSet = new DataSet();

locDataAdapter. Fill(locDataSet , "Loc");

mcs3Connection. Close();

return locDataSet.Tabl es["Loc"];

}

private void BindComboBox()

{

//disable event while processing

cboItemLoc.Sele ctedIndexChange d -= new
System.EventHan dler(cboItemLoc _SelectedIndexC hanged);

DataTable locTable = GetItemLocList( );
//debug combo box - force a few loc_PartNo loc_location values

ArrayList locations = new ArrayList();

locations.Add(" 500-000 | Prime");

locations.Add(" 500-000 | new");

locations.Add(" 100-000 | Prime");
cboItemLoc.Data Source = locations; //this was the DataTable locTable

//cboItemLoc.Disp layMember = "loc_PartNo ";

//cboItemLoc.Valu eMember = "loc_PartNo ";

//enable event

cboItemLoc.Sele ctedIndexChange d += new
System.EventHan dler(cboItemLoc _SelectedIndexC hanged);

}

Nov 16 '05 #1
1 10299
Dear NG,

Forgive me for asking first and then looking at the NG later. Mr. William
Ryan had the answer in his very excellent web site. It turned out to be
DataColumn. Here is the code that did the trick:

//use DataColumn to concatinate the Primary Key.

DataColumn dcKey = new DataColumn();

dcKey.DataType = System.Type.Get Type("System.St ring");

dcKey.ColumnNam e = "KeyString" ; //this is passed to the combo box

dcKey.Expressio n = "loc_PartNo + ' | ' + loc_location";

locTable.Column s.Add(dcKey);
cboItemLoc.Data Source = locTable;

cboItemLoc.Disp layMember = "KeyString" ;

cboItemLoc.Valu eMember = "KeyString" ;

Cheers,

Bob
"Robert Schuldenfrei" <bo*@s-i-inc.com> wrote in message
news:c94Xc.3136 71$%_6.5369@att bi_s01...
Dear NG,

I have successfully bound a combo box to a table when only one column was
involved. I am trying to present the user with the primary key to an
item-location table. The primary key involves two columns, loc_PartNo and
loc_location. My method: GetItemLocListi ng() works fine and returns the
DataTable that I instantiate to locTable. I can not get the combo box to
display and select both parts of the Primary Key. To test the combo box I
have established three examples of Primary Keys in the ArrayList: locations. For ease of parsing, I have inserted the pipe character ("|") between the
two columns. This works fine. I can think of a number of ways to approach this problem, but so far nothing has worked due to my limited knowledge of
C#, SQL, and ADO.NET. Here are my thoughts:

1/ Get the data directly out of the DataTable. I would need to "explain" to the .ValueMember where each part of the Primary Key is such that it displays both parts.

2/ Some how assign the ArrayList to the concatenated columns of the Primary Key. In an ideal world this would be done indirectly by over-laying the
ArrayList on top of the DataTable.

3/ Although it would be inefficient, copy each row of the DataTable into the ArrayList.

Any and all suggestions would be appreciated,

Bob

Robert Schuldenfrei
bo*@s-i-inc.com

private void frmFindLoc_Load (object sender, System.EventArg s e)

{

BindComboBox();

//Make sure Tag property is set even if no scrolling is done.

this.Tag = cboItemLoc.Sele ctedValue;

}

public static DataTable GetItemLocList( )

{

SqlConnection mcs3Connection = MCS3_DB.GetConn ection();

string selectStmt = "SELECT loc_PartNo, loc_location FROM ItemLoc ORDER BY "
+ "loc_PartNo , loc_location";

SqlCommand selectCommand = new SqlCommand(sele ctStmt, mcs3Connection) ;

mcs3Connection. Open();

SqlDataAdapter locDataAdapter = new SqlDataAdapter( selectCommand);

DataSet locDataSet = new DataSet();

locDataAdapter. Fill(locDataSet , "Loc");

mcs3Connection. Close();

return locDataSet.Tabl es["Loc"];

}

private void BindComboBox()

{

//disable event while processing

cboItemLoc.Sele ctedIndexChange d -= new
System.EventHan dler(cboItemLoc _SelectedIndexC hanged);

DataTable locTable = GetItemLocList( );
//debug combo box - force a few loc_PartNo loc_location values

ArrayList locations = new ArrayList();

locations.Add(" 500-000 | Prime");

locations.Add(" 500-000 | new");

locations.Add(" 100-000 | Prime");
cboItemLoc.Data Source = locations; //this was the DataTable locTable

//cboItemLoc.Disp layMember = "loc_PartNo ";

//cboItemLoc.Valu eMember = "loc_PartNo ";

//enable event

cboItemLoc.Sele ctedIndexChange d += new
System.EventHan dler(cboItemLoc _SelectedIndexC hanged);

}

Nov 16 '05 #2

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

Similar topics

3
2003
by: NB | last post by:
Let's say in the product table I have around 50,000 products (well, infact it has now about 2000 only, but it's growing very fast, hence the question here) In the order form, users will select the product for the order lines. They want to see the entire list of available products. You can't handle the combo the way you've heard: limiting rowsource until first few characters entered, because - the product primary key is an autonumber
1
3353
by: James | last post by:
I am used to VB6 but need to develop something in .Net. I need to create several bound combo-boxes which will use lookup tables to get their values. I created a form using the dataform wizard. As part of the setup, I specified a new dataset, which included the data & lookup tables. I also specified the relationships when required. I then added a combo box control to my form, following the instructions from
9
1461
by: Mark | last post by:
I am encountering a problem with the combo box. This only happens when using the datasource property, I create a table with the following values (a, b, c, d). Step 1. Select the "c" value from the drop down list by typing "c" into the combo box. Then click off from the combo to say a button. Have the button populate a text box with the combo boxes text property. Result = "a" Step 2. Repeat step 1, but type in "b" this time.
2
6940
by: Jeremy Dillinger | last post by:
I have a program setup to pull data from a database. My database table has things such as (category, Item, price, etc.) In my program I want to have multiple list boxes that will have a pull down list of different categories. The category is stored as a number and the item is stored as a string. Also once the item is picked from the list I would also like to extract the price corresponding to the chosen item. This program will be to...
10
1897
by: Richard | last post by:
I have created a form which sets up a dataview. The form views one record at a time using a currencymanager. This works fine. All my text boxes bind. However I have a combo box which gets its lookup values from another (Advertising) table (AdvertisingID, Advertising). This works .. However, where it doesn't work as well is when the form loads, the combo boxes should bind to the AdvertisingID field and display the respective data.
3
8234
by: rlm | last post by:
This small problem to solve involves a two table database (one parent and one child table), one winform and two combo boxes. Combo box A is populated in the Load event. Combo box A pulls data from the parent table. A second combo box (box B) will be populated (from the child table) based on data selected in by the user in combo box A. In the datastore the child contains a numeric foreign key from the parent.
0
1982
by: northshore | last post by:
Hello, I am creating a windows application database. I have a primary table 'Individuals' and a lookup table 'Prefixes.' In the Individuals table, I have a column 'PrefixID' that references values of prefixes from the Prefix table based on the PrefixID in the Prefix table. When I load a windows application form, I can display and update data from the primary table. This includes the prefixID value. If I display a combo box with...
4
2899
by: virtualgreek | last post by:
Dear All, First of all I would like to take the time to thank you all for your efforts and time spent at this wonderful forum. I have found it very helpful with numerous examples available for every level of user. I am facing a rather weird behaviour with a combo box on a subform (Continuous form). I have two tables. Order and Order_Details. The master form is based on the Orders tables and the details form (subform) is based on the...
1
2360
by: Tim | last post by:
I'm working on a form where a combo box gets its list of values from a table. That same table also contains some "default notes" in other fields. My task is simple, but I'm having a hard time working it out. Once an option is selected in the combo box, I want to run (a macro?) that will grab the appropriate default notes from the table, and load them into the form in the various Notes fields. I've got a query set up that'll narrow the...
2
2021
by: =?Utf-8?B?ZnJlZGR5?= | last post by:
I am new to the whole c# thing, I now how to get data from a db into a combo box. My question is: should I have one table for 5 combo box or have 5 tables for 5 combo box?
0
7936
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
8227
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...
1
5738
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5402
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();...
0
3853
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3893
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1469
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1203
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.