473,761 Members | 1,808 Online
Bytes | Software Development & Data Engineering Community
+ 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(s tr)
Dim cmd As SqlCommand = New SqlCommand("SEL ECT E1.EmployeeID,
E1.Title," & _
"E2.FirstNa me + ' ' + E2.LastName AS ReportsTo,E1.Fi rstName," &
_
"E1.LastNam e FROM Northwind..Empl oyees AS E1 LEFT OUTER JOIN" &
_
" Northwind..Empl oyees 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.Da taSource = ds.Tables("empl oyees")
cboreportsto.Di splayMember = "ReportsTo"
cboreportsto.Va lueMember = "EmployeeID "
txtid.DataBindi ngs.Add("text", ds, "employees.empl oyeeid")
txtfirstname.Da taBindings.Add( "text", ds,
"employees.firs tname")
txtlastname.Dat aBindings.Add(" text", ds,
"employees.last name")
cboreportsto.Da taBindings.Add( "text", ds,
"employees.Repo rtsTo")

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

cmd = cn.CreateComman d
cmd.CommandText = "updateemployee s"
cmd.CommandType = CommandType.Sto redProcedure
AddHandler cboreportsto.Te xtChanged, AddressOf cbochanged
With cmd.Parameters
.Add(New SqlParameter("@ employeeid", SqlDbType.NVarC har, 50)).Value =
txtid.Text
.Add(New SqlParameter("@ lastname", SqlDbType.NVarC har,
10)).Value = txtlastname.Tex t
.Add(New SqlParameter("@ firstname", SqlDbType.NVarC har,
10)).Value = txtfirstname.Te xt
.Add(New SqlParameter("@ Reportsto", SqlDbType.Int, 40)).Value =
cboreportsto.Se lectedValue

End With
Try
cmd.ExecuteNonQ uery()
MTIA,
Grawsha
Nov 20 '05 #1
4 1739
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*********@ya hoo.com> wrote in message
news:66******** *************** ***@posting.goo gle.com...
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(s tr)
Dim cmd As SqlCommand = New SqlCommand("SEL ECT E1.EmployeeID,
E1.Title," & _
"E2.FirstNa me + ' ' + E2.LastName AS ReportsTo,E1.Fi rstName," &
_
"E1.LastNam e FROM Northwind..Empl oyees AS E1 LEFT OUTER JOIN" &
_
" Northwind..Empl oyees 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.Da taSource = ds.Tables("empl oyees")
cboreportsto.Di splayMember = "ReportsTo"
cboreportsto.Va lueMember = "EmployeeID "
txtid.DataBindi ngs.Add("text", ds, "employees.empl oyeeid")
txtfirstname.Da taBindings.Add( "text", ds,
"employees.firs tname")
txtlastname.Dat aBindings.Add(" text", ds,
"employees.last name")
cboreportsto.Da taBindings.Add( "text", ds,
"employees.Repo rtsTo")

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

cmd = cn.CreateComman d
cmd.CommandText = "updateemployee s"
cmd.CommandType = CommandType.Sto redProcedure
AddHandler cboreportsto.Te xtChanged, AddressOf cbochanged
With cmd.Parameters
.Add(New SqlParameter("@ employeeid", SqlDbType.NVarC har, 50)).Value =
txtid.Text
.Add(New SqlParameter("@ lastname", SqlDbType.NVarC har,
10)).Value = txtlastname.Tex t
.Add(New SqlParameter("@ firstname", SqlDbType.NVarC har,
10)).Value = txtfirstname.Te xt
.Add(New SqlParameter("@ Reportsto", SqlDbType.Int, 40)).Value =
cboreportsto.Se lectedValue

End With
Try
cmd.ExecuteNonQ uery()
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******@hotma il.com> wrote in message news:<OJ******* *******@tk2msft ngp13.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.Select edItem and ComboBox.Select edValue 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
7686
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 different record, any changes in the current record are saved to an Access Database, the DataTable's Row Collection is Cleared and the New Record is read into the DataTable. (This is done to ensure that when the User goes to view a record, they get...
0
1503
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 and make a few TabPages 2. put a ComboBox on the one of them 3. run this code and move to the TabPages where the ComboBox sits 4. select some item of the ComboBox and move to the other TabPage
2
10264
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 "descr", and datasource to the array of MyObjects. How can i set the selected value of that combobox based on the ValueMember OR how can i find the index of an item in the combobox BY ValueMember?
2
1570
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 be able to enter data into my grid cell using a combobox. I want the combobox to display items based on my selected DisplayMember and update the datasource based on my selected ValueMember. So far, so good. But when the user leaves the combobox...
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 change the SelectedIndex of this Combo Box by using the ValueMember or DisplayMemver values. I mean the "Companies.CompanyID" or "Companies.CompanyName".
30
4601
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 corresponding field in the lookup table. In my data table we store the ID in what I will call the 'key' field. == Description of the desired operation:
2
1895
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 appear to reflect the new dataset. The same code seems to work fine if the combobox is set to the dataset on initialisation. What have I done wrong? The code in full that I'm using to update the dataset and attach to the combobox is as follows...
7
4566
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 (called "Data") with two columns "Id" and "Description". Id contains a code and description contains the description that is displayed in the combobox.
1
4250
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 object when text is deleted. However bound object contains old value in this case. To reproduce: 1. Run code
0
10136
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9925
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
8814
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5266
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
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
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.