473,511 Members | 17,577 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6763
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
2075
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
5851
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
3275
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
1890
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
8811
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
1459
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
4397
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
395
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
5756
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
7356
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,...
1
7085
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
7512
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...
1
5069
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...
0
3227
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...
0
3214
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1577
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 ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
449
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...

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.