Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Very Basic Data Binding Issue (ListBox updating)

 

Hello All,

 

I went through a video tutorial (via http://www.franklins.net/videos.asp) on basic databinding but am not able to get the same results and it's driving me nuts. I've used databinding before but have no clue about this very simple scenario.

 

Here's the scenario: I created a new vb.net Windows App project in VS.Net 2003 Pro. I then dragged a database table (from Server Explorer) to the form to create a connection and adapter, then generated a dataset (dsEmployees). I then added a ListBox, 2 TextBoxes and a DataGrid to the form. I bound the components to the dataset (listbox & one textbox to emp_lname, other textbox to emp_address or whatever, and datagrid to Employees table).

 

When I edit the emp_lname field in the datagrid and move off the field (i.e. select another row or field), the ListBox and TextBox correctly display the change. Also, when I make a change to the emp_lname field in the TextBox and then click on the *datagrid*, all 3 components correctly display the change.

 

Here's the problem: when I edit the emp_lname field via the textbox and click on the ListBox, the datagrid correctly displays the new value (from the just-edited TextBox) but the last name in the ListBox is not updated.

 

My Question: why is the ListBox correctly updated (after a change has been made to the textbox) *only* when I click on the datagrid and not when I click on the ListBox. In other words, what event is getting triggered when the datagrid is selected and not triggered when the ListBox is selected?

 

Thanks for your expertise on this very simple problem.

 

Troy

Edited by Troy_Dot_Net
  • *Experts*
Posted

Not sure if this will help, but try a call to DataRow.EndEdit(). My hunch is that editing in the DataGrid will call BeginEdit() behind the scenes. Clicking on the grid may call EndEdit() behind the scenes. Calling it explicitly may solve this for you.

 

BeginEdit/EndEdit are used per row to start editing a row. In other words, you could have an "Edit" button on a form with all bound textboxes. The DataSet would NOT get the updated data as you tabbed through each control until EndEdit is called. This "Edit" mode behavior, defined through BeginEdit/EndEdit, allows you the flexibility of adding your "Edit" button and "Cancel"/"Commit" buttons.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

>Not sure if this will help, but try a call to DataRow.EndEdit(). My hunch is that editing in the DataGrid will call BeginEdit() behind the scenes. Clicking on the grid may call EndEdit() behind the scenes. Calling it explicitly may solve this for you.

 

Thanks for your idea. In what method/event do you suggest I put the call to EndEdit()?

 

It seems strange to me that editing the textbox and then clicking on the listbox updates the datagrid but not the listbox, whereas editing the textbox and then clicking on the datagrid updates BOTH the datagrid and the listbox.

 

Troy

  • *Experts*
Posted

I'd try putting the EndEdit behind a button, to test.

A question: how are you binding the ListBox? Can you zip up your project and post it so we can help out?

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

Any chance you could provide the sraclc.mdb file (in your "\Shared\Projects\sraclc\EasyKeys\bin\" folder)? Can't really test without it.

 

I could probably fake a DataSet for testing, but not help you as much. If you can't give out the DB, just let me know and I'll fake one.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...