Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This is Stupid How do I use a List View Controll? 2

Status
Not open for further replies.

Hawkeye123456

Programmer
May 5, 2000
24
0
0
US
I Need to use a list view control to displaya list in 2 Columns.  Then I want to be able to edit the entries through code and not let the user edit them.  I know how to put the headders on, but I dont know how to edit the data that is in them, or even how to put data in them.  Thanks in advance
 
List Views are tricky, but look upon it as a collection, just one where you can see all the objects in that collection in a window.&nbsp;&nbsp;I've not been using them long, but here's how I'm populating a listview with three column headers (not defined here, I set them in the control properties window) from a recordset:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;lstMenu.ListItems.Clear<br>&nbsp;&nbsp;&nbsp;&nbsp;Do Until rs.EOF<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set itm = lstMenu.ListItems.Add(, , rs!HTMLLinkID)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itm.SubItems(1) = rs!HTMLStyleID<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;itm.SubItems(2) = rs!HTMLLinkName<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rs.MoveNext<br>&nbsp;&nbsp;&nbsp;&nbsp;Loop<br><br>First I clear the list, then I loop through the recordset and use the set itm (where itm is a listitem object defined as: Dim itm As MSComctlLib.ListItem in this module) to add a new listitem object to the listview control.&nbsp;&nbsp;As the listview has three columns, so each listview item object will have three fields.&nbsp;&nbsp;Performing an ADD method will allow you to set the first field (here, I'm setting it to rs!HTMLLinkID from my recordset).&nbsp;&nbsp;To put stuff in the next two columns, you have to set the SubItem properties (indexed from 1 to the number of columns in the listview control) of the itm object you're currently setting up - which is what I do in the next two lines.&nbsp;&nbsp;Now the itm object contains everything I want and I've used the ADD method to place it in the listview control, the last thing I do before looping back is to move to the next record in my recordset.<br><br>&nbsp;&nbsp;You can then refer to each item in the listview as an individual object either by its numeric index (I think) or you can assign each list item a KEY when you add it and refer to it by that. I haven't here, but it'd go in the ADD method arguments as the second argument: <br><br>Set itm = lstMenu.ListItems.Add(, &lt;Key Goes Here&gt;, rs!HTMLLinkID)<br><br>Hope that helps - they're not bad once you get in to them I've found :)<br><br>Cheerio then,<br><br>Paul<br><br>
 
Cool Paul thanks.&nbsp;&nbsp;I am not going to be using a record set for all of them, but I bet I can use your description to figure our how get make them work.&nbsp;&nbsp;Thanks again.<br><br><br>--Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top