473,951 Members | 3,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

binding a combobox to a specific column in a DataTable

2 New Member
hello :)

I want to bind a combobox to a specific column in a DataTable.
I want the combobox items to display distinct values.

I tried:
combo.datasourc e = dataTable;
combo.DisplayMe mber = "DESIRED COLUMN";

(here I got the values I want, but including empty rows, and with repetitions).
I tried to iterate and check the text of the items, but I can't do "visible = false" since I iterate over datarows,
and I can't remove the specific item from the combobox, since I bound the combobox to a datatable via the datasource property.

do anyone have an idea?

thanks, anat :)
Aug 25 '09 #1
2 8326
cloud255
427 Recognized Expert Contributor
Hi, this is why I don't use databindings... you just lose so much control.

What is suggest is that that you loop through the datatable and check if the current item should exist in the items collection of the combobox. If it should then you simply call the Add method to add the item to the combobox.
Aug 25 '09 #2
anatanat
2 New Member
sorry for the big delay in resonding, but thanks for your help :)
this is what I did at the end

(I iterated over the items in the desired column, and created a dictionary with the values as the key (if it's not contained already in the dictionary) in order to get distinct values only, and then I took all the keys from the dictionary and inserted it to the combobox).
Sep 9 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
7500
by: Omar | last post by:
When I try to databind my comboBox (specifically field "emplcode") to a filled dataset , the contents of the comboBox displays a bunch of "System.Data.DataRowView". I assume the amount of times "System.Data.DataR..." is displayed inside the combobox is the amount of records in the dataset. On the other hand, if my query is "select emplcode from payemployee", the databind will work fine (but I don't want to limit the dataset to one field)....
0
1095
by: David | last post by:
Hello, I practice C#, and I would like to change the style of a specific column in a Windows Forms DataGrid - into a ComboBox. Namely, when the user selects that specific column (in any row), he will see a ComboBox which is binded to a specific column in table B, while the DataGrid is binded to table A. Any help will be appreciated. Thanks,
0
1560
by: Leeor Chernov | last post by:
Hi , I am using the method: DSSap.ReadXml( XmlPath,XmlReadMode.InferSchema ); And as I expected I get an error when the xml does not matching my DataSet that contains already a schema , The problem is that I get the following to-much detailed message: System.FormatException: Input string was not in a correct format. at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Int32.Parse(String s,...
0
273
by: Eran.Yasso | last post by:
Hello all, This is my first time using listview. I was looking in google for a way to write to a specific column. I have 3 columns in my list view. I want to be able to write to a specific one. Also, it seems that even when i set listview to have 3 colums, there's a fourth one with no header. How can I remove it and have only 3
0
1322
by: Problematic coder | last post by:
Hi, I have just been asked to create an app that will import a specific column from an excel spreadsheet, something like sheet1 columnD or a column with the first row with a value of 'ID' whichever would be easier. The rest of what I need to do once I have the data I am ok with but the connecting to the spreadsheet and extracting a column into an array or dataset or whatever would work best I have no clue. I would appreciate some...
6
14224
convexcube
by: convexcube | last post by:
After searching the web for a solution to total a specific column in a list box and not finding it, I came up with this: Dim varTotal As Currency Dim varRow As Integer For varRow = 1 To (lstListbox.ListCount - 1) varTotal = varTotal + lstListbox.Column(2, varRow) Next txtTotal = varTotal This will provide a total in txtTotal for the third column (referenced as "2" because the first column is "0") in the list box as currency.
7
26409
by: cesco | last post by:
Hi, I have a file containing four columns of data separated by tabs (\t) and I'd like to read a specific column from it (say the third). Is there any simple way to do this in Python? I've found quite interesting the linecache module but unfortunately that is (to my knowledge) only working on lines, not columns. Any suggestion?
2
2203
by: sukatoa | last post by:
I have a table, where it composed of several columns, but i am concerning only on a specific column with datatype varchar under that db table... Now, for example: column: links values: http://localhost/asdf/asdf.php http://localhost/ http://localhost/12312/adfdf.php
0
11607
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11198
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
11375
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,...
1
8270
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
6237
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
6357
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4968
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
2
4555
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3563
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.