473,574 Members | 3,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

List Control Binding requires two data sources


I am trying to populate a list control that is bound to a data table
but the display member needs to come from a different data table.

I have two list controls in C#, one displaying available categories and
one displaying selected categories. In the database these are
represented in two tables, the available category table has an ID and a
Name. The other table is a category links table that has an ID,
Category_ID and a Book_ID.

The first list control works fine with the following code and it
successfully displays the names of the categories:

// Specify bindings for the available categories.
m_lstAvailableC ategories.DataS ource = m_dtCategories;
m_lstAvailableC ategories.Displ ayMember = "Category_Name" ;
m_lstAvailableC ategories.Value Member = "Category_I D";
m_lstAvailableC ategories.DataB indings.Add("Te xt", m_dtCategories,
"Category_I D");

My problem occurs when displaying the selected categories in the other
list control. This data is gathered from the category links table. I
have applied a row filter on the table to leave me only the rows that
match the Book_ID that I have specified. Ideally I would like to
display the Category Name in the list control but the problem I have is
that it does not know the category name, all I have is the category ID
and the Book ID. I think my problem is that the DisplayMember value
must reside in the table associated with the DataSource and this list
has its DataSource set to the category links table. I am getting the
correct rows returned, but all it displays is the Category IDs and that
is not any help to me.

I have this code so far and it's not working as expected, can anyone
point me in the right direction or is this just not possible?

// Specify bindings for selected categories.
m_lstSelectedCa tegories.DataSo urce = m_dtCatLinks;
m_lstSelectedCa tegories.Displa yMember = "Category_Name" ;
m_lstSelectedCa tegories.ValueM ember = "Category_I D";
m_lstSelectedCa tegories.DataBi ndings.Add("Tex t", m_dtCategories,
"Category_I D");



Jan 10 '06 #1
4 2043
I've been thinking about this problem a little bit more and I have a
feeling my problem is not that I need to bind my list control to two
datasources and then use the rowFilter to display the categories that
only interest me for a particular book. Instead, maybe the selected
categories list control should be unbound and I populate it myself
every time a book is selected performing a lookup on both the data
tables to obtain the details I need to display.

It would be nice if there was a clever way I could have it bound as it
makes updating the database much easier.

Does anyone have any suggestions that might help me make the right



Jan 10 '06 #2
I built something like this a while back. Some thoughts (assuming that
you're programming WinForms and not WebForms).

First, I believe that Microsoft's way of doing this is with a ListView
with Checkboxes. At least, that's what I'm using now. That's why the
two data sources: what is showing, and what is currently selected. They
do it all within one control.

Back when I had two lists instead of a single ListView with checkboxes,
what I did was build my own UserControl that contained the two lists
(exactly as you described) and the controls necessary to move items
from the "unselected " list to the "selected" list and vice versa. Your
UserControl could then expose the appropriate properties for the
binding (i.e. all items and selected items) and take care of mediating
between data and display (i.e. Category ID versus Name, etc).
Practically speaking, you could tailor the UserControl to the binding,
rather than trying to jigger the binding to your controls.

Jan 10 '06 #3
Thanks for the suggestion, I'll take a look at building my own user
control (I've not done that before).. The checked list box is a good
idea but I don't think it would quite work for what I wanted to do..
The categories can have sub-categories that are more specialised, that
you can drill down into. e.g. Sports could have the sub-categories
Football and Rugby. I could have a book that has a selected category of
sports and I could have another book that has been assigned a more
specific category of Football.

The only way I could think of displaying that, is to have buttons that
drill down into a category etc, and then you select the categories
(there could be multiple) that apply to a book. I wanted to see at a
glance, what categories have been assigned to a book and I don't think
I could do that easily with a checked list box.



Jan 11 '06 #4
I've just been looking at the user defined control and that will
basically just allow me to put all the category functionality into one
new form that will then I guess get embedded into my main form. I am
still not sure I'd be able to bind my list controls to the database
tables that I would like to populate them from. The available
categories is easy enough but because the selected categories requires
the details from the category links table to identify what categories
were chosen by this particular book and also the ability to be able to
lookup the category name from the category table that has been bound to
the available categories.

I still think I need to manually manage the contents of the selected

Jan 11 '06 #5

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

Similar topics

by: Ed West | last post by:
Hi, I am dynamically creating Comboboxes and putting them in a panel. However, they are all referencing the same object! When I change one, then all of them change. How can I make it so it doesn't do this? I'm sure this is pretty simple, just can't find the answer. Thanks. for (int i=0; i < _ds.Tables.Columns.Count; i++) { ComboBox x...
by: Biva | last post by:
Hello, I have a drop down list control in a datagrid. I can't seem to populate the control. Here is what my code looks like: <EditItemTemplate> <asp:DropDownList ID= "ddlUser5" DataSource = '<%# ddlUser5Bind() %>' Runat =server> </asp:DropDownList> </EditItemTemplate>
by: reiks | last post by:
I have a dropdownlist control . I want to bind the data to it from an existing datagrid on my page i.e I wnat to specify the datagrid name instead of the datatable name. Is it possible? How can I bind data from a datagrid to ddlistbox?
by: Leszek Taratuta | last post by:
Hello, I have several drop-down lists on my ASP.NET page. I need to keep data sources of these lists in Session State. What would be the most effective method to serialize this kind of data structures? Thanks for any hints, Leszek Taratuta
by: JV | last post by:
It's easy to databind a listbox or dropdownlist if all you want is to fill it with a list of values. There are plenty of examples in the online help. Unfortunately, real world applications demand more. Usually you would also like to bind the SelectedValue to something else. Common scenario: You have an ADDRESS table with a foreign key...
by: Brian Henry | last post by:
Well here is the problem, I have a data set with about 9,000 to 20,000 people in it in the data table "people"... I am then reading it into a list view one at a time row by row... adding each person to the list view, well this works fine up to about 1,000 people then it start's to get really show putting the people in (a lot of process time...
by: cipcip | last post by:
hi, is there a way to bind a menu control with a dataset without get this error? System.InvalidOperationException: HierarchicalDataBoundControl only accepts data sources that implement IHierarchicalDataSource or IHierarchicalEnumerable. I've tryed this , but it doesn't render correctly and write the menu
by: gnewsgroup | last post by:
OK, I am still trying to achieve something like what is shown in the following PNG image. http://farm3.static.flickr.com/2066/1808692173_ea202973a3_o.png I thought about doing this with a plain Table server control, but the problem is that this control does not provide enough events for us to identify the row in which the button is...
by: =?Utf-8?B?V29ua28gdGhlIFNhbmU=?= | last post by:
Hello, I have a custom control (not a listbox or other hierarchical or list control) that I would like to bind to a specific row and column from a DataTable. Each row of the datatable will have columns like PropertyName, IsEnabled, CurrentValue, etc. In my control, I want to show the CurrentValue of a property with a
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...
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...
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...
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...
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...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
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...

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.