473,667 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Referencing ID column in 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, assuming that
databinding 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 for doing what I
tried to do?

Thanks!


Nov 20 '05 #1
2 1214
Cor
Please do not multipost,

The answer is given below
by Eduardo A. Morcillo [MS MVP VB]
Nov 20 '05 #2
Sorry for the multipost. My newsreader crashed while I was submitting, and
it didn't appear as though the message posted. Thanks for your response.

"Cor" <no*@non.com> wrote in message
news:uY******** *****@TK2MSFTNG P11.phx.gbl...
Please do not multipost,

The answer is given below
by Eduardo A. Morcillo [MS MVP VB]

Nov 20 '05 #3

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

Similar topics

4
2989
by: Giulio | last post by:
Hello, I have a continuous form with a combo box inside. From the combo box I can pick some values which, by the "after-update" event, change some other combo box values determined by a query. (i.e. I have some tree names and depending on what tree I pick on the other combo box I can pick its fruits and other properties) Now, mine is a continous form, and whenever I pick a value from the first combo box the second one correctly shows...
6
2872
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).. ...
4
1607
by: Raed Sawalha | last post by:
i have datagrid , I added a bound column and I need to map it with two data fields ...is this possible? <asp:datagrid id=dgInbox runat="server" EnableViewState="False" AutoGenerateColumns="False" AllowSorting="True" Width="100%"> <ItemStyle Wrap="False" BorderWidth="11px" BorderStyle="Solid" CssClass="tableCell"></ItemStyle> <HeaderStyle Height="26px" CssClass="tableHeaderCell"></HeaderStyle> <Columns> <asp:BoundColumn...
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()...
7
4529
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
3036
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
1700
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!)
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
924
by: trint | last post by:
I want to bind just the first column from a sql query to a list box so that it only contains the first column results. Like: listBox1_______ 101 201 301 401____________ I already have the data bound (but it's the whole row) to a datagridview:
0
8459
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
8889
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
8790
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...
0
8650
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
7391
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...
0
5677
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
4202
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
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2781
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

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.