Troy_Dot_Net Posted October 12, 2005 Posted October 12, 2005 (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 October 12, 2005 by Troy_Dot_Net Quote
*Experts* Nerseus Posted October 12, 2005 *Experts* Posted October 12, 2005 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 Quote "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
Troy_Dot_Net Posted October 12, 2005 Author Posted October 12, 2005 >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 Quote
*Experts* Nerseus Posted October 12, 2005 *Experts* Posted October 12, 2005 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 Quote "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
Troy_Dot_Net Posted October 13, 2005 Author Posted October 13, 2005 (edited) >Can you zip up your project and post it so we can help out? Can do!DataBindingTest.zip Edited October 13, 2005 by PlausiblyDamp Quote
*Experts* Nerseus Posted October 13, 2005 *Experts* Posted October 13, 2005 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 Quote "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
Troy_Dot_Net Posted October 13, 2005 Author Posted October 13, 2005 Attached is a stripped down version of the sraclc.mdb (Employees table only). Note that the mdb and ZIP file are both named sraclc_employees--this will need to be changed in the vb.net code. Thanks for your assistance and ideas. :) Troysraclc_employees.zip Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.