473,626 Members | 3,276 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Listbox, DataView, DataTable, and System.Data.Dat aRowView

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 = "MenuEntryI d";

private void populateMenu()
{
DataView dv = _ds.Tables["Menu"].DefaultView;
// have tried new DataView(_ds.Ta bles["Menu"]) too
dv.RowFilter = string.Format(" {0} = '{1}'", MENUID, menuId);
// lbMenu.ValueMem ber = MENU_ENTRY_ID; // topic 1 for discussion
lbMenu.DataSour ce = dv;
lbMenu.DisplayM ember = ITEM;
}

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

foreach (DataRow dr in dt.Rows)
{
if(Convert.ToIn t32(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.Da taRowView" 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 6777
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
2088
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 DataView with 2 columns and 3 rows Dim ADOHelper As New DAL.ADOHelper Return ADOHelper.GetMyDataview() End
1
5856
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
3291
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 the selected lie item at which case I would pop up a separate dialog box to do so, in the debugging code, the dataview.count would return 0. I get a error message because I tried to get values out of a dataview that holds 0 items. Does anyone...
3
1903
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 eliminate the time. As an example, SQL Server returns: 2004-04-18 00:00:00.000. Instead, I want: 4/18/2004. Is there a way to alter the format in which the DataView displays a table's rows without having to alter data source? As a (hopefully)...
5
8824
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 happen. Dim objKeys(2) as Object objKeys(0) = "CL" objKeys(2) = 4000 Dim posView As DataView = New DataView(posDS.Tables("Positions"), _
3
1472
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, i'm having trouble getting the selected items in the listbox. Will simply using the Items property (with the index) not give me
5
4405
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 by 1 or more selected items from the listbox on the right after clicking an Add button. Clicking a "Remove" button will remove the item from the left listbox and restore it back to the right box.
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" , MENU_ENTRY_ID = "MenuEntryId"; private void populateMenu() {
3
5761
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 used to move item from/to the 1st and 2nd listbox My problem here is that after I bind the data to the 1st listbox (from a dataTable, using DisplayMember and ValueMember), and I try to move 1 of the item from this 1st listbox to the 2nd listbox...
0
8269
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8711
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8642
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8512
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 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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7203
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5576
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4094
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2630
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 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.