RC1, Listbox databinding

RC1, Listbox databinding

Post by Mike Hanlo » Thu, 10 Jan 2002 12:36:52



Hello

I have a dataset table created with the following select:

SELEXT EmpID, Surname, GivenName, Surname + ', ' +
GivenName AS FullName FROM Employees ORDER BY Surname,
GivenName

EmpID is an identity column and is the primary key.

Surname and GivenName are bound to textboxes and Fullname
is bound to a listbox as ...
DataSource = "Employees"
DisplayMember = "FullName"
ValueMember = "EmpID"
SelectedItem = "Employees.EmpID"

How do I move the position of the data in the textboxes in
response to the listbox's SelectionChanged event?

Thank you.

 
 
 

RC1, Listbox databinding

Post by Mike Hanlo » Fri, 11 Jan 2002 17:19:55


Hello

I have a dataset table created with the following select:

SELEXT EmpID, Surname, GivenName, Surname + ', ' +
GivenName AS FullName FROM Employees ORDER BY Surname,
GivenName

EmpID is an identity column and is the primary key.

Surname and GivenName are bound to textboxes and Fullname
is bound to a listbox as ...
DataSource = "Employees"
DisplayMember = "FullName"
ValueMember = "EmpID"
SelectedItem = "Employees.EmpID"

How do I move the position of the data in the textboxes in
response to the listbox's SelectedIndexChanged event?

I have tried ...
me.BindingContext(ds,"Employees").position =
ListBox1.SelectedIndex

but I get the error: "EmpID" is read-only

Thank you.

 
 
 

RC1, Listbox databinding

Post by Lion S » Fri, 11 Jan 2002 23:10:00


Hello Mike,

You can use a BindingManagerBase to manage the data binding. You can use it
like a navigator. This is a sample code of BindingManagerBase:

BindingManagerBase bmCustomers;
?-?-
textSurname.DataBindings.Add(new System.Windows.Forms.Binding("Text", ds, "
Employees. Surname"));
bmSurname = this.BindingContext [ds, " Employees "];
?-...
bmSurname.Position = listFullname.SelectedIndex;

For more information about BindingManagerBase please see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpre...
frlrfSystemWindowsFormsBindingManagerBaseClassTopic.asp

Alternatively, you can fill the text box by yourself by using the
SelectedItem property. The SelectedItem is a DataRowView. It is more
flexible:

DataRowView row = (DataRowView) listFullname.SelectedItem;
textName.Text = row["Surname "] + " " + row["GivenName"];

I hope this is helpful.

Best regards,

Lion Shi, MCSE, MCSD
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.  2001 Microsoft Corporation. All rights
reserved.
--------------------
Content-Class: urn:content-classes:message


Subject: RC1, Listbox databinding
Date: Tue, 8 Jan 2002 19:36:52 -0800
Lines: 22

MIME-Version: 1.0
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
Thread-Index: AcGYvuCpuD+Uiqm9QmOxpyDYSh0toA==
Newsgroups: microsoft.public.dotnet.framework.windowsforms
NNTP-Posting-Host: TKMSFTNGXA13 10.201.226.41
Path: cpmsftngxa09!cpmsftngxa07
Xref: cpmsftngxa09 microsoft.public.dotnet.framework.windowsforms:8721
X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms

Hello

I have a dataset table created with the following select:

SELEXT EmpID, Surname, GivenName, Surname + ', ' +
GivenName AS FullName FROM Employees ORDER BY Surname,
GivenName

EmpID is an identity column and is the primary key.

Surname and GivenName are bound to textboxes and Fullname
is bound to a listbox as ...
DataSource = "Employees"
DisplayMember = "FullName"
ValueMember = "EmpID"
SelectedItem = "Employees.EmpID"

How do I move the position of the data in the textboxes in
response to the listbox's SelectionChanged event?

Thank you.