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

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
LVL 1
jsctechyAsked:
Who is Participating?
 
Praveen KumarArchitectCommented:
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
 
DhaestCommented:
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
 
Praveen KumarArchitectCommented:
if you want to disply twio columns, better to go with ListView control, which have more properties and options.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
jsctechyAuthor Commented:
>>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
 
DhaestCommented:
I would also take a look at the listview instead of the listbox...
Or a datagrid ...
0
 
jsctechyAuthor Commented:
how can i do it with a listview?
0
 
jsctechyAuthor Commented:
is that C++?
i'm working on VB .NET
0
 
jsctechyAuthor Commented:
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
 
Praveen KumarArchitectCommented:
sorry for that,
IMPORTANT:

change the View property to Details for the ListView
0
 
jsctechyAuthor Commented:
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
 
jsctechyAuthor Commented:
hahahahaha i feel dumb

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

listView.items.Clear ()

thanks for all your help
0
 
Praveen KumarArchitectCommented:
glad to help you.
thanks for your points, which gave me a premiem membership.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.