Drstein99 Posted May 31, 2004 Posted May 31, 2004 When I bind a datatable to a textbox: tb1.DataBindings.Add("TEXT", esTableName, ncFieldname) How do I indicate WHAT row or currently selected row it's bound to? Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
JABE Posted June 1, 2004 Posted June 1, 2004 Set the position of the CurrencyManager associated w/ the Textbox's datasource. For instance, to move to the next record: Dim cm As CurrencyManager = CType(TextBox1.DataBindings("Text").BindingManagerBase, CurrencyManager) If cm.Position < cm.Count Then cm.Position += 1 End If Quote
*Experts* Nerseus Posted June 1, 2004 *Experts* Posted June 1, 2004 You can also go through the form, which has a BindingContext for all controls. For example, to move to the next row for all bound controls: Me.BindingContext(esTableName).Position = Me.BindingContext(esTableName).Position + 1 -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
Drstein99 Posted June 1, 2004 Author Posted June 1, 2004 It seems to be stuck on "0" no matter what i do with the ".position". Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
*Experts* Nerseus Posted June 1, 2004 *Experts* Posted June 1, 2004 First, are you sure you have more than one row? Maybe we can see your code for binding and for changing the position. You must make sure that whatever you supply as the DataSource to the textbox's binding is the EXACT same as the one used on Me.BindingContext(...). It won't work if they're "the same" but coded differently. For example, you can bind a textbox to the exact same thing, two different ways (assume a variable ds as a DataSet was defined earlier): textBox1.DataBindings.Add("Text", ds, "Table1.Column1") textBox1.DataBindings.Add("Text", ds.Tables("Table1"), "Column1") Although they point to the exact same data in the exact same dataset, the binding context is setup differently. If you bound the textbox the first way and tried moving position on the form using the following, it wouldn't work: textBox1.DataBindings.Add("Text", ds, "Table1.Column1") Me.BindingContext(ds.Tables("Table1")).Position = Me.BindingContext(ds.Tables("Table1")).Position + 1 In the same above, you'd have to use the BindingContext as: textBox1.DataBindings.Add("Text", ds, "Table1.Column1") Me.BindingContext(ds.Tables("Table1")).Position = Me.BindingContext(ds).Position + 1 Of course, are you sure you've got the textbox bound correctly? Is it showing some data from your DataSet, just won't move off the first row? -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
Drstein99 Posted June 1, 2004 Author Posted June 1, 2004 I'm binding using the datatable, and column name: textbox1.databindings.add("text",custDataTable,"employee") This works fine. i then destroy the text box. Later on in the program, i will add a row using .insertat (to that same custDataTable object). When i repeat the databind command, it always sticks to the original record (at position "0"), not the newly inserted one (which is the one i want). if i check the .count propert it shows "2" (in the watch box) i'm not doing anything with ".table1", i just use the datatable object, and no tables off the datatable. so i'm not binding to a datasource, i'm binding to a datatable. Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
*Experts* Nerseus Posted June 1, 2004 *Experts* Posted June 1, 2004 When you say you "repeat the databind" command, can I assume you are clearing the old databinding first? Does your Position code look something like: Me.BindingContext(custDataTable).Position = Me.BindingContext(custDataTable).Position + 1 If all this fails, I'll try to duplicate it here. -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
Drstein99 Posted June 1, 2004 Author Posted June 1, 2004 I'm binding useing the tb1.databindings.add(...... command. I didnt read anywhere in the VAGUE documents I had to clear the databindings. I .dispose the tb1. object after i'm done using it (basically when a user goes to another page). When the user returns to that page then the code creates a new tb1. object and new databindings. This process repeats throughout. I'm not using "me" object. This is a function held in a module thats called from the form. My code is similar to your example, online instead of "me" i use the tb1 object. Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
Drstein99 Posted June 1, 2004 Author Posted June 1, 2004 P/S: If I have to CLEAR databindings, how do u reccomend is the best way I do that because microsoft help file doesnt mention that or anything like it, in the helpfile for adding databindings. ? Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
Drstein99 Posted June 1, 2004 Author Posted June 1, 2004 Update: I experimented with databindings.remove. BEFORE I dispose the textbox object, I am removing all the databindings from it using the "REMOVEAT" command. Then I .dispose the textbox When I execute the code .position += 1, it now MOVES the position correctly as I expect. Aparantly the old databindings interfeared with this. Which had not been made clear to me that I had to remove databinding when I added it. I figured the help file would instruct me to remove them before i dispose of the object but anyway - you live and learn... thanks for help, case closed. Quote www.DRSTEIN99.com www.RAIDGEAR.net www.THERE.com -> Tell them DrStein99 sent ya!
*Experts* Nerseus Posted June 2, 2004 *Experts* Posted June 2, 2004 I'm not sure why you're disposing the TextBox... But, you shouldn't normally have to remove a binding. Normally your code should bind controls when the form loads (or before) and never again. Or, bind controls per Tab, if you use a TabControl. It sounds like you may be using some common code in a Module to create and manage controls. Without knowing how/when your code is being called, it's impossible to guess when the binding would work - from my point of view. I AM glad you got it working though :) -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
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.