473,606 Members | 2,825 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning ID from Listbox bound to DataTable

I've got a list box bound to a Datatable, like this:

lstProjects.Dat aSource = m_oProjectSet.D ataTable
lstProjects.Dis playMember = "ProjectDes c"
lstProjects.Val ueMember = "ProjectID"

I want to pass the ProjectID value (integer) of the selected item in
lstProjects to another function.

I assumed I could reference the integer value of the ProjectID column as
lstProjects.Sel ectedValue, since I set it's ValueMember property to
"ProjectID" . I discovered that SelectedValue returns a DataRowView.

Through trial and error I found that I can get to the integer value with:

lstProjects.Dat aSource.Default View(lstProject s.SelectedIndex ).Item("Project I
D")
or
m_oProjectSet.D ataTable.Defaul tView(lstProjec ts.SelectedInde x).Item("Projec t
ID")

Seems like a lot of code to do something so simple and so common. (I know
it's one line, but it should be shorter, and more intuitive, given that data
binding should make things like this simple.)

Is there a simpler expression that would give me the integer value?

What is the purpose of the ValueMember property, if not that which I tried
to use it?

Thanks!
Nov 20 '05 #1
6 2227
> Is there a simpler expression that would give me the integer value?

lstProjects.Sel ectedValue

--
Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo
Nov 20 '05 #2
This returns a datarowview. How do get the integer value?

"Eduardo A. Morcillo [MS MVP]" <emorcilloATmvp s.org> wrote in message
news:%2******** **********@TK2M SFTNGP12.phx.gb l...
Is there a simpler expression that would give me the integer value?


lstProjects.Sel ectedValue

--
Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo
Nov 20 '05 #3
Cor
Hi Young,

I dont see it not more today but show some more of your code or be sure that
in this piece of code "ProjectID" is exactly right

lstProjects.Val ueMember = "ProjectID"

Let us know if this was the error will you?

And otherwise the code with wich you fill your datatable or dataset.

Cor
Nov 20 '05 #4
Thanks again for your response.

My original post is included below. DataTable is a property of type
DataTable of an object m_oProjectSet, which is a private variable in the
form.
It's just a DataTable. By that I mean that it is not part of a DataSet. I'm
pretty sure I've coded it the way you mention below.

I'm sure the DataTable is filled correctly, because the correct rows and
values are there when I reference them directly, and the values display
correctly in the list box. (I'd post the code, but I use seperate data
access components, and I'd have to post three different complete class
listings for you to trace how the table gets filled and past to the business
object.)

I was hoping for a simple way to get the integer value directly from the
list box.

-----------------

I've got a list box bound to a Datatable, like this:

lstProjects.Dat aSource = m_oProjectSet.D ataTable
lstProjects.Dis playMember = "ProjectDes c"
lstProjects.Val ueMember = "ProjectID"

I want to pass the ProjectID value (integer) of the selected item in
lstProjects to another function.

I assumed I could reference the integer value of the ProjectID column as
lstProjects.Sel ectedValue, since I set it's ValueMember property to
"ProjectID" . I discovered that SelectedValue returns a DataRowView.

Through trial and error I found that I can get to the integer value with:

lstProjects.Dat aSource.Default View(lstProject s.SelectedIndex ).Item("Project I
D")
or
m_oProjectSet.D ataTable.Defaul tView(lstProjec ts.SelectedInde x).Item("Projec t
ID")

Seems like a lot of code to do something so simple and so common. (I know
it's one line, but it should be shorter, and more intuitive, given that data
binding should make things like this simple.)

Is there a simpler expression that would give me the integer value?

What is the purpose of the ValueMember property, if not that which I tried
to use it?

Thanks!

"Cor" <no*@non.com> wrote in message
news:OI******** ******@TK2MSFTN GP12.phx.gbl...
Hi Young,

I dont see it not more today but show some more of your code or be sure that in this piece of code "ProjectID" is exactly right

lstProjects.Val ueMember = "ProjectID"

Let us know if this was the error will you?

And otherwise the code with wich you fill your datatable or dataset.

Cor

Nov 20 '05 #5
> I've got a list box bound to a Datatable, like this:

lstProjects.Dat aSource = m_oProjectSet.D ataTable
lstProjects.Dis playMember = "ProjectDes c"
lstProjects.Val ueMember = "ProjectID"


Then SelectedValue (NOT SELECTEDITEM!!! ) returns the value of the column with the ValueMember name of the selected item.

--
Eduardo A. Morcillo [MS MVP VB]
http://www.mvps.org/emorcillo
Nov 20 '05 #6
Cor
Hi Young,

This is so not my kind of stuff, but this I keep it with the last respond of
me.

I think in that one ore the other way the listbox does not accept your
property from your table as a valuemember
lstProjects.Dat aSource.Default View(lstProject s.SelectedIndex ).Item("Project I D") I think also that here is written (you reference direct to the table)
table.rows(inde x).item("Projec tId)
m_oProjectSet.D ataTable.Defaul tView(lstProjec ts.SelectedInde x).Item("Projec t ID")


And that is the same
table.rows(inde x).item("Projec tId)

So I agree with you that it is strange?

Cor
Nov 20 '05 #7

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

Similar topics

6
2866
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset a denormalized mirror of the database, but I'm not having much luck getting the selection logic down (I haven't found a 'hook' where I can access the listbox object as an object to set the listitem's selected property before it gets rendered).. ...
6
1552
by: Sparky Arbuckle | last post by:
The code below works to an extent. The problem with it is that no matter which item is selected, the first one in the list is always the item that gets added/removed. How can I alleviate this problem? I have tried If Not Page.IsPostBack and still nothing. Private Sub btnCol1ToCol2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCol1ToCol2.Click Dim s As String = lbColumn1.SelectedItem.Text()...
3
3838
by: David L Wright II | last post by:
I have a data bound listbox that I want to select multiple lines then process each line. I bound a two column datatable to the listbox and set the DisplayMember property to the appropriate column of the datatable. I set the SelectionMode property to MultiExtended. I am able to load and select multiple lines in the listbox but I can not figure out how to retrieve both columns for each line selected in the listbox. I know that there is...
7
4526
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but ASP.Net stuff when I need a Windows Form control. I've seen dual listbox populators in countless Windows applications, and have seen them run very fast, so I figured this would be extremely popular. Here's how it should work:
1
3035
by: Spock | last post by:
Hi. I have a form with a listbox and a few label fields all bound to a dataset. When i navigate the listbox the labels change accordingly. so far everything works good. I made a button to delete a record. I delete the row from the datatable and update the database with the adapter and that all works good. The record is removed from the listbox. Here is my problem.
7
1696
by: Zorpiedoman | last post by:
I'm confused. I have a listbox. The DataSource is a DataTable based on a SQL Select Statement that includes a where clause. For example, "Select ID, FirstName, LastName From Employees where DepartmentID = 5" I have three controls on the same form that are bound to this datatable. So far so good. I click through the list in the listbox, and the controls reflect the current selected item in the listbox. (Nice!)
1
1868
by: cptkirkh | last post by:
I havea listbox bound to a datatable. When the form loads it thinks the first item is selected. Is there anyway to tell the listbox when it loads not to select the first time automatically?
15
13496
by: Joseph Geretz | last post by:
I'm a bit puzzled by the current recommendation not to send Datasets or Datatables between application tiers. http://support.microsoft.com/kb/306134 http://msdn2.microsoft.com/en-us/library/ms996381.aspx Formerly, with classic Microsoft DNA architecture, the ADO Recordset was a primary transport medium, recommended for transmitting data between application tiers. In fact, there are whole books written on the subject.
2
1908
by: Randy | last post by:
I have two listboxes on a form. The first box displays categories while the second box displays the items belonging to the category selected in the first box. Thus, the second box is essentially display only. I'm trying to sort these lists alphabetically A->Z. I have the Sort property set to True. When I run the app, the items in each box are sorted correctly. So far, so good. What I am confused by is that when a category is...
0
8045
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
7981
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
8127
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
8320
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5470
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
3952
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...
1
2458
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
1
1574
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1315
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.