473,497 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Combobox doesnot update valuemember??

al
Greetings,

As I understands it, SelectedValud of combobox reads its value from
ValueMember property of the combobox. This doesn't work with me. What
happens is just randome update. This is the code,
'Here I set connectin and commands

Dim cn As SqlConnection = New SqlConnection(str)
Dim cmd As SqlCommand = New SqlCommand("SELECT E1.EmployeeID,
E1.Title," & _
"E2.FirstName + ' ' + E2.LastName AS ReportsTo,E1.FirstName," &
_
"E1.LastName FROM Northwind..Employees AS E1 LEFT OUTER JOIN" &
_
" Northwind..Employees AS E2 ON E2.EmployeeID = E1.ReportsTo",
cn)
Dim ds As New DataSet
Dim da As New SqlDataAdapter(cmd)
'This fills dataset and initializes combobox values

da.Fill(ds, "employees")
cboreportsto.DataSource = ds.Tables("employees")
cboreportsto.DisplayMember = "ReportsTo"
cboreportsto.ValueMember = "EmployeeID"
txtid.DataBindings.Add("text", ds, "employees.employeeid")
txtfirstname.DataBindings.Add("text", ds,
"employees.firstname")
txtlastname.DataBindings.Add("text", ds,
"employees.lastname")
cboreportsto.DataBindings.Add("text", ds,
"employees.ReportsTo")

'Here I do update to database, but no update real happens, just
randome one

cmd = cn.CreateCommand
cmd.CommandText = "updateemployees"
cmd.CommandType = CommandType.StoredProcedure
AddHandler cboreportsto.TextChanged, AddressOf cbochanged
With cmd.Parameters
.Add(New SqlParameter("@employeeid", SqlDbType.NVarChar, 50)).Value =
txtid.Text
.Add(New SqlParameter("@lastname", SqlDbType.NVarChar,
10)).Value = txtlastname.Text
.Add(New SqlParameter("@firstname", SqlDbType.NVarChar,
10)).Value = txtfirstname.Text
.Add(New SqlParameter("@Reportsto", SqlDbType.Int, 40)).Value =
cboreportsto.SelectedValue

End With
Try
cmd.ExecuteNonQuery()
MTIA,
Grawsha
Nov 20 '05 #1
4 1720
You're binding to the Text Property, try SelectedValue. I can't remember if
it's SelectedValue or SelectedIndex, but I'm 99% sure it's the first one.

HTH,

Bill
"al" <gr*********@yahoo.com> wrote in message
news:66**************************@posting.google.c om...
Greetings,

As I understands it, SelectedValud of combobox reads its value from
ValueMember property of the combobox. This doesn't work with me. What
happens is just randome update. This is the code,
'Here I set connectin and commands

Dim cn As SqlConnection = New SqlConnection(str)
Dim cmd As SqlCommand = New SqlCommand("SELECT E1.EmployeeID,
E1.Title," & _
"E2.FirstName + ' ' + E2.LastName AS ReportsTo,E1.FirstName," &
_
"E1.LastName FROM Northwind..Employees AS E1 LEFT OUTER JOIN" &
_
" Northwind..Employees AS E2 ON E2.EmployeeID = E1.ReportsTo",
cn)
Dim ds As New DataSet
Dim da As New SqlDataAdapter(cmd)
'This fills dataset and initializes combobox values

da.Fill(ds, "employees")
cboreportsto.DataSource = ds.Tables("employees")
cboreportsto.DisplayMember = "ReportsTo"
cboreportsto.ValueMember = "EmployeeID"
txtid.DataBindings.Add("text", ds, "employees.employeeid")
txtfirstname.DataBindings.Add("text", ds,
"employees.firstname")
txtlastname.DataBindings.Add("text", ds,
"employees.lastname")
cboreportsto.DataBindings.Add("text", ds,
"employees.ReportsTo")

'Here I do update to database, but no update real happens, just
randome one

cmd = cn.CreateCommand
cmd.CommandText = "updateemployees"
cmd.CommandType = CommandType.StoredProcedure
AddHandler cboreportsto.TextChanged, AddressOf cbochanged
With cmd.Parameters
.Add(New SqlParameter("@employeeid", SqlDbType.NVarChar, 50)).Value =
txtid.Text
.Add(New SqlParameter("@lastname", SqlDbType.NVarChar,
10)).Value = txtlastname.Text
.Add(New SqlParameter("@firstname", SqlDbType.NVarChar,
10)).Value = txtfirstname.Text
.Add(New SqlParameter("@Reportsto", SqlDbType.Int, 40)).Value =
cboreportsto.SelectedValue

End With
Try
cmd.ExecuteNonQuery()
MTIA,
Grawsha

Nov 20 '05 #2
Yes, it is SelectedValue.

I just went through this with my program!

Good luck,

Gary
Nov 20 '05 #3
al
"Bo Diddly" <hd******@hotmail.com> wrote in message news:<OJ**************@tk2msftngp13.phx.gbl>...
Yes, it is SelectedValue.

I just went through this with my program!

Good luck,

Gary

Thanks Guyes! The randome assignment of combobox is gone after I had
changed text property to SelectedValue. But now there is another
problem. When I load the form and navigate with next and prev. it
works fine, but the problem is when I change the vaule in the combobox
to another one. That is, When I select a value from the list, then
the previous selected value becomes the default in the combobox's
selected value for all records when I move next or prev. It seems to
me that the ValueMember of the combobox becomes out-of-synch and does
not change as the selected value in combobox changes, thusly affecting
the SelectedValue of the combobox.

Any feedback is greatly apprciated!!!
Nov 20 '05 #4
Grawsha,

Try setting the ComboBox.SelectedItem and ComboBox.SelectedValue to the same
value.

Gary
(was Bo Diddly but now is Didymus)
Nov 20 '05 #5

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

Similar topics

0
7666
by: Timothy White | last post by:
I have a Windows Form Which Displays one record at a time. The DataTable object which is bound to the Form Controls only contains the record that is being displayed. When I need to display a...
0
1480
by: CalPARK InterNetStation | last post by:
Could anyone explain why the difference of behavior betweein Case1 and Case2 occurs? Microsoft Visual C#.NET 55607-652-0000007-18218 Windows Forms Application 1. put a TabControl on a Form...
2
10239
by: farseer | last post by:
Hi, I have a combobox who's data source i set to an array of objects (call it MyObject). these objects have get properties: key, value, descr. i set ValueMember to "key", DisplayMember to...
2
1554
by: pmcguire | last post by:
OK. So I've been to http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp and learned a lot about what I might do with a datagrid. But I'm STILL not able to do what I want to do. I want to be able...
3
916
by: Nikolay Petrov | last post by:
I have a Combo box, binded to a dataset With cmbCompany .DataSource = dsSpecContact .DisplayMember = "Companies.CompanyName" .ValueMember = "Companies.CompanyID" End With What I want is to...
30
4510
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
2
1875
by: Simon Verona | last post by:
I have a combobox that is contained within a user control. Whilst the application is running, I'm attaching the combobox to a new dataset. The problem I'm getting is that the combobox doesn't...
7
4549
by: Simon Verona | last post by:
I posted this in dotnet.languages.vb.controls but thought I'd post here as well.. I have a combobox that is bound to a dataview generated from a dataset. The dataset has a single table...
1
4205
by: Andrus | last post by:
I need to enter null value from combobox to business object property. My combobox datasource does not contain ValueMember with null value. So I tried to create combobox which stores null to bound...
0
7160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6878
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...
0
7373
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3088
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
286
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...

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.