473,659 Members | 2,920 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Data Binding to Textbox

Hi,

I'm trying to create a form that shows table rows in a listbox. Several
comboboxes expand the foreign key fields into text values from the parent
tables, and there are also some textboxes for the non-foreign key fields.
When the user clicks on a row in the listbox, the comboboxes' SelectedItem
changes to reflect the foreign key selections in the currently selected row.
That part is working fine. I also want the textboxes to change to reflect
the currently selected item's values.

I created a DataBinding in the textbox (actually, it's a custom control,
NumericTextBox, which only allows numeric values). The field that is bound
to the NumericTextBox is of type int. The property it is bound to (IntValue)
is of type Int32 (although I've tried many different types with no luck).
I've also tried using a plain textbox to no avail.

The problem is that, initially, the NumericTextBox displays the correct
value for the initially selected row. But if I enter that text box, I can't
leave it. And if I change the value of it, when I press tab, it changes back
to what it was. Also, if (before clicking it) I change to a different row in
the listbox, all the comboboxes update, but the textbox does not. What's
going on?

***
Private Sub PaperEditor_Loa d(ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Initialize data binding for listbox.
lbPaperSelector .DataSource = internalDataSet .Paper 'The main paper
table, with foreign keys galore.
lbPaperSelector .DisplayMember = "FullText"
lbPaperSelector .ValueMember = "ID"

'Set selected item to the first paper listed.
lbPaperSelector .SelectedIndex = 0

'Initialize combo boxes.
cbSupplier.Data Source = internalDataSet .Supplier 'The parent
tables to table Paper. Lots more of these in the actual code.
cbSupplier.Disp layMember = "Name"
cbSupplier.Valu eMember = "ID"
cbSize.DataSour ce = internalDataSet .Size
cbSize.DisplayM ember = "Name"
cbSize.ValueMem ber = "ID"

'Initialize text boxes.
tbItemNumber.Da taBindings.Add( "IntValue",
DirectCast(lbPa perSelector.Sel ectedItem, DataRowView).Ro w, "ItemNumber ")
End Sub

Private Sub lbPaperSelector _SelectedIndexC hanged(ByVal sender As Object,
ByVal e As System.EventArg s) Handles lbPaperSelector .SelectedIndexC hanged
'Update combo boxes.
cbSupplier.Sele ctedValue =
DirectCast(Dire ctCast(lbPaperS elector.Selecte dItem, DataRowView).Ro w,
Papers.PaperRow ).Supplier
cbSize.Selected Value =
DirectCast(Dire ctCast(lbPaperS elector.Selecte dItem, DataRowView).Ro w,
Papers.PaperRow ).Size
End Sub

Apr 20 '07 #1
1 6417
Peter,

Have a look at the binding events at MSDN

Cor

"Peter" <st*****@hotmai l.comschreef in bericht
news:4V******** ********@newsre ad2.news.pas.ea rthlink.net...
Hi,

I'm trying to create a form that shows table rows in a listbox. Several
comboboxes expand the foreign key fields into text values from the parent
tables, and there are also some textboxes for the non-foreign key fields.
When the user clicks on a row in the listbox, the comboboxes' SelectedItem
changes to reflect the foreign key selections in the currently selected
row. That part is working fine. I also want the textboxes to change to
reflect the currently selected item's values.

I created a DataBinding in the textbox (actually, it's a custom control,
NumericTextBox, which only allows numeric values). The field that is bound
to the NumericTextBox is of type int. The property it is bound to
(IntValue) is of type Int32 (although I've tried many different types with
no luck). I've also tried using a plain textbox to no avail.

The problem is that, initially, the NumericTextBox displays the correct
value for the initially selected row. But if I enter that text box, I
can't leave it. And if I change the value of it, when I press tab, it
changes back to what it was. Also, if (before clicking it) I change to a
different row in the listbox, all the comboboxes update, but the textbox
does not. What's going on?

***
Private Sub PaperEditor_Loa d(ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Initialize data binding for listbox.
lbPaperSelector .DataSource = internalDataSet .Paper 'The main
paper table, with foreign keys galore.
lbPaperSelector .DisplayMember = "FullText"
lbPaperSelector .ValueMember = "ID"

'Set selected item to the first paper listed.
lbPaperSelector .SelectedIndex = 0

'Initialize combo boxes.
cbSupplier.Data Source = internalDataSet .Supplier 'The parent
tables to table Paper. Lots more of these in the actual code.
cbSupplier.Disp layMember = "Name"
cbSupplier.Valu eMember = "ID"
cbSize.DataSour ce = internalDataSet .Size
cbSize.DisplayM ember = "Name"
cbSize.ValueMem ber = "ID"

'Initialize text boxes.
tbItemNumber.Da taBindings.Add( "IntValue",
DirectCast(lbPa perSelector.Sel ectedItem, DataRowView).Ro w, "ItemNumber ")
End Sub

Private Sub lbPaperSelector _SelectedIndexC hanged(ByVal sender As
Object, ByVal e As System.EventArg s) Handles
lbPaperSelector .SelectedIndexC hanged
'Update combo boxes.
cbSupplier.Sele ctedValue =
DirectCast(Dire ctCast(lbPaperS elector.Selecte dItem, DataRowView).Ro w,
Papers.PaperRow ).Supplier
cbSize.Selected Value =
DirectCast(Dire ctCast(lbPaperS elector.Selecte dItem, DataRowView).Ro w,
Papers.PaperRow ).Size
End Sub

Apr 20 '07 #2

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

Similar topics

3
1468
by: Jow Blow | last post by:
Hello All, In two different books, Simple Data Binding to a control is explained with an example of a TextBox where the data is initialized with an array. For example a class is defined as such: public class Vendor {
0
2795
by: Wesman | last post by:
Why does the following code not work (displays the correct values in the second textbox). if i chane the OnFocusChange method to the following it will work: private void OnFocusChange(object sender, System.ComponentModel.CancelEventArgs e) { Control control = (Control) sender; control.BindingContext.EndCurrentEdit(); results.Text = test.BindingTestString;
0
1451
by: Wesman | last post by:
Why does the following code not work (displays the correct values in the second textbox). if i chane the OnFocusChange method to the following it will work: private void OnFocusChange(object sender, System.ComponentModel.CancelEventArgs e) { Control control = (Control) sender; control.BindingContext.EndCurrentEdit(); results.Text = test.BindingTestString;
4
1972
by: Alan Silver | last post by:
Hello, I'm trying to use an ArrayList to do data binding, but am getting an error I don't understand. I posted this in another thread, but that was all confused with various other problems, which could be why no-one answered it!! I've now narrowed the problem down, so am starting a new, more specific, thread. Sorry it's a bit long, but it's reasonably simple stuff. I have a page where I'm showing product details, including any
3
3792
by: alan | last post by:
What I would like to do is like that, a ListView data binding with a dataset which list all records of a table( for example the table list all the information of a student student_id, name, tel....etc). Besides, there are some textbox will display the student information when I click on one of the record on the ListView so that I can update the records in the textbox. I can do the data binding for the ListView and the dataset, butI don't...
7
4206
by: Andrew McKendrick | last post by:
Hi, I've noticed a bug in VB.NET (latest .NET Framework)... - I have a TabControl on a form with several tabs. - Each tab contains text boxes that are bound to fields in a data source (DataBindings). - When I display a record and then try to access the .Text property of one of the text boxes on any tab except the current tab, the result is an Empty string.
0
1518
by: Larry Serflaten | last post by:
I am not sure how many are aware of this sort of data binding, but as it is new to many (classic) VB developers I thought I would post this once just to let people know of its availablility. There are cases where properties of one object is dependant on a property of another object. For a common example, when you bind an ArrayList to a ComboBox using the combo's DataSource property, the combo box fills up with items from the array list....
0
1485
by: AM | last post by:
The following block of code defines a FormView control "FormView1" with an EditItemTemplate which has a Label and a TextBox control within it. While the Label "RequestIDLabel1" has one-way data-binding to the underlying column "RequestID", the TextBox "RequestDateTextBox" has two-way data-binding to the underlying column. If I were to generate the EditItemTemplate dynamically at runtime, and add the Label and TextBox controls at...
0
1841
by: EricLondaits | last post by:
Hi, I have an ASP.NET page with a ListBox that is data bound to a table with a single field (it holds a list of valid IDs). The page also has a textBox into which you can add new valid IDs, one per line (this is in order to make the process of adding new IDs easy, since it's only done at time of configuration). I have no problem with retrieving the contents of the textBox, splitting it into a string array, validating the individual...
5
1600
by: raajakumars | last post by:
urgent!!!!!!! kindly please anyone help me....... actualy i am newbe to vb.net i need data to be inserted in to my table like this... sitenm cdate wrknm nowrk totwg tamiz palace 12/1/2007 Electrician 34 5100 tamiz palace 12/1/2007 Mason 5 900 instead my following code produces result like this..
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8335
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8528
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.