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

ListBox Datatable changes reflected immediately, but out of sync??

I'm confused.

I have a listbox. The DataSource is a DataTable based on a SQL Select
Statement that includes a where clause. For example, "Select ID, FirstName,
LastName From Employees where DepartmentID = 5"

I have three controls on the same form that are bound to this datatable. So
far so good. I click through the list in the listbox, and the controls
reflect the current selected item in the listbox. (Nice!)

Ok, here's where it gets weird. If I change the departmentID to 6 for one
of the rows, that employee disappears from the list box. At first I thought
this was really cool, but when clicking on items in the list now, the
databinding is out of sync.

Let's say I changed the first employee in the list to DepartmentID =6. It
disappears from the list. If I click on the second item in the list, I see
field values for the first item. If I click on the first item on the list, I
see field values for the changed employee that is no longer in the list.

What is happening, and how do I fix it?

--
--Zorpie
Nov 21 '05 #1
7 1683
As a separate, but related question, why is it that clicking on an item in
the listbox moves the position of the datatable? I have not set up any
connections to a BindingManagerBase or anything like that. It's a nice
convenience (maybe) but I need to understand how this is working so I can
control it better.

Thanks in advance...
--
--Zorpie
"Zorpiedoman" wrote:
I'm confused.

I have a listbox. The DataSource is a DataTable based on a SQL Select
Statement that includes a where clause. For example, "Select ID, FirstName,
LastName From Employees where DepartmentID = 5"

I have three controls on the same form that are bound to this datatable. So
far so good. I click through the list in the listbox, and the controls
reflect the current selected item in the listbox. (Nice!)

Ok, here's where it gets weird. If I change the departmentID to 6 for one
of the rows, that employee disappears from the list box. At first I thought
this was really cool, but when clicking on items in the list now, the
databinding is out of sync.

Let's say I changed the first employee in the list to DepartmentID =6. It
disappears from the list. If I click on the second item in the list, I see
field values for the first item. If I click on the first item on the list, I
see field values for the changed employee that is no longer in the list.

What is happening, and how do I fix it?

--
--Zorpie

Nov 21 '05 #2
Hi,

"Zorpiedoman" <no*********@beatles.com> wrote in message
news:87**********************************@microsof t.com...
I'm confused.

I have a listbox. The DataSource is a DataTable based on a SQL Select
Statement that includes a where clause. For example, "Select ID,
FirstName,
LastName From Employees where DepartmentID = 5"

I have three controls on the same form that are bound to this datatable.
So
far so good. I click through the list in the listbox, and the controls
reflect the current selected item in the listbox. (Nice!)
That shouldn't happen automatically. Normally you have to use a DataView
and set the RowFilter to "DepartmentID = 5" for this to happen.

Ok, here's where it gets weird. If I change the departmentID to 6 for one
of the rows, that employee disappears from the list box. At first I
thought
this was really cool, but when clicking on items in the list now, the
databinding is out of sync.

Let's say I changed the first employee in the list to DepartmentID =6. It
disappears from the list. If I click on the second item in the list, I
see
field values for the first item. If I click on the first item on the
list, I
see field values for the changed employee that is no longer in the list.

What is happening, and how do I fix it?
Are you by any change handling either SelectedIndexChanged or any of the
other Selected Changed events ?

Be carefull that you do not cause an exception inside, because they are
masked (hidden) and cause problems like you are describing.

So everything inside SelectedIndexChanged should be put inside a try/catch
and inside catch display the error, so you can see if anything goes wrong.

hth,
greetings


--
--Zorpie

Nov 21 '05 #3
Hi,
"Zorpiedoman" <no*********@beatles.com> wrote in message
news:B6**********************************@microsof t.com...
As a separate, but related question, why is it that clicking on an item in
the listbox moves the position of the datatable? I have not set up any
connections to a BindingManagerBase or anything like that. It's a nice
convenience (maybe) but I need to understand how this is working so I can
control it better.
Because the Control are bound to the same DataSource ( DataTable in this
case ) and they share the same BindingContext(default) so they will use the
same CurrencyManager (keeps position) and navigate together.

Hth,
Greetings

Thanks in advance...
--
--Zorpie
"Zorpiedoman" wrote:
I'm confused.

I have a listbox. The DataSource is a DataTable based on a SQL Select
Statement that includes a where clause. For example, "Select ID,
FirstName,
LastName From Employees where DepartmentID = 5"

I have three controls on the same form that are bound to this datatable.
So
far so good. I click through the list in the listbox, and the controls
reflect the current selected item in the listbox. (Nice!)

Ok, here's where it gets weird. If I change the departmentID to 6 for
one
of the rows, that employee disappears from the list box. At first I
thought
this was really cool, but when clicking on items in the list now, the
databinding is out of sync.

Let's say I changed the first employee in the list to DepartmentID =6.
It
disappears from the list. If I click on the second item in the list, I
see
field values for the first item. If I click on the first item on the
list, I
see field values for the changed employee that is no longer in the list.

What is happening, and how do I fix it?

--
--Zorpie

Nov 21 '05 #4

"> That shouldn't happen automatically. Normally you have to use a DataView
and set the RowFilter to "DepartmentID = 5" for this to happen."
EXACTLY... This should not happen. Yet I am not setting up any filters, and
it DOES happen... I thought that to be really 'interesting.'
Are you by any change handling either SelectedIndexChanged or any of the
other Selected Changed events ?

Be carefull that you do not cause an exception inside, because they are
masked (hidden) and cause problems like you are describing.

So everything inside SelectedIndexChanged should be put inside a try/catch
and inside catch display the error, so you can see if anything goes wrong.


I am, but there are no errors occuring.
Nov 21 '05 #5
I'll keep responding to my own questions, and maybe I'll figure it out
myself...

Anyway, in looking at the call stack, changing the selectedindex of the
listbox is calling the Set_Position method of the form's Bidning context.

I did nothing to set this up, it seems automatic.

Where is someone from MS to help with this question???

-zorpid
Nov 21 '05 #6
Hi,

"Zorpiedoman" <no*********@beatles.com> wrote in message
news:CC**********************************@microsof t.com...

"> That shouldn't happen automatically. Normally you have to use a
DataView
and set the RowFilter to "DepartmentID = 5" for this to happen."
EXACTLY... This should not happen. Yet I am not setting up any filters,
and
it DOES happen... I thought that to be really 'interesting.'
Are you by any change handling either SelectedIndexChanged or any of the
other Selected Changed events ?

Be carefull that you do not cause an exception inside, because they are
masked (hidden) and cause problems like you are describing.

So everything inside SelectedIndexChanged should be put inside a
try/catch
and inside catch display the error, so you can see if anything goes
wrong.


I am, but there are no errors occuring.


Are you sure? Seems a little coincidental that you are handling
SelectedIndexChanged and seeing this problem. Have you put everything
inside a try/catch ? Have you tried completely removing (commenting out)
the SelectedIndexChanged handlers to see if it works ?

Hth,
Greetings

Nov 21 '05 #7
Hi,

"Zorpiedoman" <no*********@beatles.com> wrote in message
news:E4**********************************@microsof t.com...
I'll keep responding to my own questions, and maybe I'll figure it out
myself...

Anyway, in looking at the call stack, changing the selectedindex of the
listbox is calling the Set_Position method of the form's Bidning context.

I did nothing to set this up, it seems automatic.
Nothing special about that. If you bind a ListBox to a DataTable there will
be a CurrencyManager created in the BindingContext of the Form. ( The
BindingContext of the Form is by default shared by all child controls. )

The CurrencyManager maintance the current position so it's normal it's
linked to the SelectedIndex of the ListBox.

hth,
Greetings


Where is someone from MS to help with this question???

-zorpid

Nov 21 '05 #8

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

Similar topics

4
by: N. Graves | last post by:
Hello... thank you for your time. I have a form that has a List box of equipotent records and a sub form that will show the data of the equipment select from the list box. Is it possible to...
0
by: Jhon | last post by:
Hi, I've a design problem... Say I have a class Item and a class ItemList. Now I want to display the items in a listbox, save and load them. This is a problem because both the listbox and...
3
by: Scott | last post by:
I'm trying to bind my listbox to a SQL query like this: using (SqlConnection conn = new SqlConnection(CONN_STR)) { using (SqlDataAdapter da = new SqlDataAdapter("roboticSiteNames", conn)) {...
1
by: MrNobody | last post by:
Hi, I'm doing something where I add custom objects to a ListBox which have aToString() method overriden so it displays what I want. When adding instances of these custom objects to the ListBox I...
0
by: Alpha | last post by:
Hi, I have a listbox and a textbox which is bind to the same dataset's column. So the selected item is display in the textbox availbe for editing. When I change the text in the textbox it has...
2
by: Alvaro E. Gonzalez V. | last post by:
Hi; I'm building a control that has a DataTable's property type. The control contains treeview which is populated in foreach crossing rows of the DataTable established in the property. I...
2
by: Luis Ferrao | last post by:
Hi, I have some code that looks like this: -- CODE ---------------------------- Public Class NodeEditor Inherits System.Web.UI.Page Protected WithEvents ChildList As...
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: Craig Buchanan | last post by:
I created a TableAdapter (TA) in my VB 2005 project. I tested it to ensure that its CRUD functionality is what I expected it to be. I'm using the TA and its strongly-typed DataTable (DT) in my...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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.