?
Solved

how to display two columns in a listBox and when is clikc have the value of the first column

Posted on 2007-10-16
13
Medium Priority
?
373 Views
Last Modified: 2013-11-26
hi,
I have a listbox that needs to display two columns like this:

REP    NAME
***      Doe
111    Smith
222    Last

i'm getting these record from a query string:
Select REP_P, Name FROM tblBrokers order by REP_P

so when the forms loads i need to display these records in columns, now i have the MultipleColumns options set to true but how do i enable to display two columns?

Thanks,
jsctechy
0
Comment
Question by:jsctechy
  • 6
  • 4
  • 3
13 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 20085388
Do you want to display the values in 2 columns ?
http://www.startvbdotnet.com/controls/listbox.aspx

Or do you want the listbox to show 2 columns (something like a grid, with in the first column rep_p and in the second column name ?)
http://www.codeproject.com/vb/net/mclb.asp
0
 
LVL 12

Expert Comment

by:Praveen Kumar
ID: 20085419
if you want to disply twio columns, better to go with ListView control, which have more properties and options.
0
 
LVL 1

Author Comment

by:jsctechy
ID: 20085439
>>Or do you want the listbox to show 2 columns (something like a grid, with in the first column rep_p and in the second column name ?)

yes, this is what i want.

But the sample you have provide me I dont see how to apply to my problem.

how do i turn my query result into an array or the same way the sample provided does?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Dhaest
ID: 20085462
I would also take a look at the listview instead of the listbox...
Or a datagrid ...
0
 
LVL 1

Author Comment

by:jsctechy
ID: 20085497
how can i do it with a listview?
0
 
LVL 12

Accepted Solution

by:
Praveen Kumar earned 2000 total points
ID: 20085516
nice to hear that...

rag the ListView into the form, and create the( two in your case) columns, from Columns property of ListView.

once you got the data into a datatable or dataset, you show in the listview like this...

  For Each row As DataRow In dtContracts.Rows
              ListViewItem item = new ListViewItem();
               item.Text=Convert.ToString(row(0));
               item.SubItems.Add(Convert.ToString(row(1)));
               ListView1.Items.Add(item);
   End For      

 




0
 
LVL 1

Author Comment

by:jsctechy
ID: 20085541
is that C++?
i'm working on VB .NET
0
 
LVL 1

Author Comment

by:jsctechy
ID: 20085679
Mamtha1982
if the code you have provide is a C# here is the equivalent in .NET  and when i execute the code below it does not display anything.

For Each row As DataRow In dt.Rows
                Dim item As New ListViewItem()
                item.Text = Convert.ToString(row(0))
                item.SubItems.Add(Convert.ToString(row(1)))
                lstRepDetails.Items.Add(item)
                ' End For
            Next

Dhaest:
You have provide me some good link but the links just show how to hard code values but i need to add values from the result set of the query string.

so to summary my progress i'm still where i started =/
0
 
LVL 12

Expert Comment

by:Praveen Kumar
ID: 20085747
sorry for that,
IMPORTANT:

change the View property to Details for the ListView
0
 
LVL 1

Author Comment

by:jsctechy
ID: 20086314
ok i see what i was doing wrong:
here is what i have done:
>>create the( two in your case) columns, from Columns property of ListView.
I did not create this so the listView did not know where to put my values ;-)

i have a question though if i'm populating my listview after i click on a buttom how do i clear the context inside the listview?
if i do listview.clear() this will not allow the listview to display any values becasue i will kind of erase the columns and their values!
how can i just emptry the values been display and show the new values?
0
 
LVL 1

Author Comment

by:jsctechy
ID: 20086347
hahahahaha i feel dumb

just add before the click event requeries the items this line:

listView.items.Clear ()

thanks for all your help
0
 
LVL 12

Expert Comment

by:Praveen Kumar
ID: 20086465
glad to help you.
thanks for your points, which gave me a premiem membership.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question