473,396 Members | 2,111 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.

Listbox, DataView, DataTable, and System.Data.DataRowView

I am experiencing some weird behaviors with the listbox and dataview.
Here is a boiled down code snippet of what I am trying to do.

<snippet>
string MENUID = "MenuId"
, ITEM = "Item"
, MENU_ENTRY_ID = "MenuEntryId";

private void populateMenu()
{
DataView dv = _ds.Tables["Menu"].DefaultView;
// have tried new DataView(_ds.Tables["Menu"]) too
dv.RowFilter = string.Format("{0} = '{1}'", MENUID, menuId);
// lbMenu.ValueMember = MENU_ENTRY_ID; // topic 1 for discussion
lbMenu.DataSource = dv;
lbMenu.DisplayMember = ITEM;
}

private void addNewEntry(int newValue)
{
// ... code checking to see if value already exists
int newMenuEntryId = GetController.AddNewRow();
// yes we are working with the same data source.

foreach (DataRow dr in dt.Rows)
{
if(Convert.ToInt32(dr[MENU_ENTRY_ID]) == newMenuEntryId)
{
dr[ITEM] = newValue;
// ... more related items
}
}
// populateMenu(); topic 2
}
</snippet>

Upon the form load event everything displays properly. I add a new
value that is to go into my list box for displaying to the end user. I
launch a new form and capture that new data point. An event is thrown
and I add the new item to the DataTable, as in the code snippet. The
interesting behavior begins.

Topic 1 discussion:
This discussion is for adding the new DataRow to the DataTable. If I
have this code uncommented and let the form move forward, my list box
shows the Value Members instead of the Display Members. If I leave the
code commented I see in the list box "System.Data.DataRowView" for my
results. (I am not able to have this piece of code after setting the
DataSouce because I receive an exception of "Cannot modify the Items
collection when the DataSouce property is set.") Regardless of the
commenting out, the ListBox shows that a new row in the underlying
source has been added.

Topic 2 discussion:
Why must I have to recreate the DataView and all the other trapings to
get the data to display properly? I should only have to set it once
and let the items do all the various updating.

Has anyone else seen this behavior? If so, where you able to overcome
the behavior without having to reset ListBox with a new DataView? I
have not started my work with deleting yet. Are there the same issues
there too?

Thank you in advance.

Aug 29 '05 #1
1 6759
I changed the sort property from true (of which I set early on) to
false on the ListBox in VS2003 IDE and then things started working as
they should. It even got rid of the "Cannot modify the Items
collection when the DataSouce property is set" exception I was seeing
too.

Weird!!!

Aug 30 '05 #2

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

Similar topics

9
by: Raymond Lewallen | last post by:
I have a dataview in which the sort property will not sort the dataview. Here's is a simple scenario similar to what I am doing: Class Foo Private Function Retrieve() As DataView ' Returns a...
1
by: TaeHo Yoo | last post by:
Hi all, After sorting and grouping data using a dataview, then how to transfer the changed datatable in the dataview to a datatable in C#? Cheers
2
by: Alpha | last post by:
I have a window application. In one of the form, a datagrid has a dataview as its datasource. Initial filtering result would give the datavew 3 items. When I double click on the datagrid to edit...
3
by: Eric Lemmon | last post by:
Greetings, I have a VB.NET Windows app where I bind a listbox to a DataView column that contains date values. In this list, however, only the date (not the time) is relavent, so I want to...
5
by: David Wender | last post by:
I want to create a dataview with a sort on multiple columns. However, when I use FindRows, I only want to search some of the columns, not all. Is this possible? I have not been able to make it...
3
by: joe | last post by:
I actually have 2 questions: 1) Is databinding the fastest way to load a listbox from sqlserver? speed is crucial and I want to make sure i'm populating it the fastest way i can 2) Also,...
5
by: Dave | last post by:
Hi All, I have a windows form that contains 2 listboxes and 2 buttons. The listbox on the right is populated by a database routine (This is the easy part). The listbox on the left is populated...
1
by: GeraldBauer | last post by:
I am experiencing some weird behaviors with the listbox and dataview. Here is a boiled down code snippet of what I am trying to do. <snippet> string MENUID = "MenuId" , ITEM = "Item" ,...
3
by: perrycheung221 | last post by:
Hi guys, I got 2 listboxes in a window form, one on left and one on right. The 1st listbox have some items while the 2nd listbox is empty. Also there are 2 buttons between the 2 listboxes which...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
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.