E
emzyme20
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
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