Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Trying to programatically change a TextBox
Message
 
To
20/02/2005 16:04:33
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00988694
Message ID:
00988959
Views:
52
Hi Bonie.
I did as you suggested and it worked up to a point

On my button that assigns the text, I ussued a :
this.BindingContext[MyBoundTable].EndCurrentEdit()
and sure enough, I could then see the text populating the text box

On My Form Save button, I already had a :
DataRowView drView = (DataRowView)this.BindingContext[MyDataset,"MYBoundTable"].Current;
drView.EndEdit();

When this code runs ,it seems to blank out the programatically created text
but all the manually entered text is OK !!

Any idea why this is happening.

regards,
Gerard







>Gerard,
>
>You didn't say whether this was a WinForm or a WebForm. If you're talking about a WebForm, then take Nancy's advice and read Rick's white paper.
>
>But, if you're talking about a WinForm, then it's a different story (and databinding *is* two-way in this case). Here's what's happening ... the data in a TextBox doesn't get "saved" to it's bound data column until the Validated event of the TextBox has occured. Since you're setting it programmatically, it's Validated event never fires. The easiest way around this it to execute the BindingContext's .EndCurrentEdit() method:
>
>this.BindingContext[MyBoundTable].EndCurrentEdit();
>
>This will "flush" the value in the TextBox.Text property into it's proper place in the DataTable.
>
>~~Bonnie
>
>
>
>>Hi.
>>I have a form, with a control on it (txtName) Databinded to a datatset, and if I amend the name on the form, it all works fine and is saved back to the table.
>>
>>However the following is happening:
>>I have a button ,and on it's Click event the following code:
>> this.txtName = 'This name has been changed";
>>When I click on the button, it does change it on the screen, but when I save the Dataset, the Database does not get changed !!
>>
>>I would have thought, because the text box is bound to the Dataset, and because it also displays on screen when I chage it, that it should be saved back to the table .
>>
>>Any body any idead of what I am doing wrong ?
>>
>>Regards.
>>Gerard
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform