troubleshooting Question

How to select a row from a listbox and get the proper value using C# with VS 2005?

Avatar of zimmer9
zimmer9Flag for United States of America asked on
.NET ProgrammingC#
3 Comments1 Solution419 ViewsLast Modified:
I am converting an application from Access 2003 VBA to a C# Windows application using VS2005.

How would you convert the following Access VBA snippet to C#?

List Box: lstCustRpts  
Row Source SELECT tblCustReports.ReportID, tblCustReports.ReportName, tblCustReports.ReportDescription FROM tblCustReports ORDER BY ReportID;

For Each vnt In lstCustRpts.ItemsSelected
        strQuery = lstCustRpts.Column(1, vnt)
        If (strQuery = "qryCuPFQ") Then
        ElseIf (strQuery = "qryCuPSQ") Then



ReportID  ReportName        ReportDescription
-----------  ----------------       ---------------------------
3                 qryCuPFQ                 ACS Fall Report
4                 qryCuPSQ                 ACS Spring Report

I tried the following C# code but I get the same value

itemText = "qryCuPFQ" for each row I select from the listbox
string selectedyear = (string)this.comboBox1.SelectedItem;
            DataRowView drv = (DataRowView)listBox3.Items[0];
            string itemText = drv.Row["ReportName"].ToString();
            if (itemText == "qryCuPFQ")
            else if (itemText == "qryCuPSQ")

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros