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

List Control Binding requires two data sources

Hi,

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_lstAvailableCategories.DataSource = m_dtCategories;
m_lstAvailableCategories.DisplayMember = "Category_Name";
m_lstAvailableCategories.ValueMember = "Category_ID";
m_lstAvailableCategories.DataBindings.Add("Text", m_dtCategories,
"Category_ID");

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_lstSelectedCategories.DataSource = m_dtCatLinks;
m_lstSelectedCategories.DisplayMember = "Category_Name";
m_lstSelectedCategories.ValueMember = "Category_ID";
m_lstSelectedCategories.DataBindings.Add("Text", m_dtCategories,
"Category_ID");

Regards,

Emma

Jan 10 '06 #1
4 2030
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
choice?

Regards,

Emma

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.

Thanks,

Emma

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
list.

Jan 11 '06 #5

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

Similar topics

1
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...
1
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 =...
1
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...
13
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...
4
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...
11
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...
1
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...
7
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...
5
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...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
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...
0
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...
0
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,...

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.