2 ListView Questions. 1 About Selecting Records. 2 About Adjusting Listview Box Size.
Hi, I'm changing some of my programs to use a ListView instead of a ListBox.
1. On selecting a record how do I pass the info from the fifth column to another Sub? (I have .FullRowSelect = True)
2. I'm dynamically adjusting the column widths to the maximum length of the data going into the column. Is there a way to dynamically adjust the width of the listview box itself to be the sum of the column widths?
Thanks, Al.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Adjusting Form Size Based On The Screen Size
I want to Set My Vb 6.0 Form Size based on the Screen Width & Height. Its important that i should extend this to all the Controls in a particular form like ToolBar,Tree View, Grid etc.,
How to acheive this? I need the Solution as a reusable code which can be put in a Module (to be used when any form gets loaded).
Thx yaar ...
.. SK ..
Selecting From Listview
I have a double click event on listview which is used to remove items - this works all fine and dandy.
The problem is if there is a double click on the blank area at the boffom on the listview where there is no data I am still getting a valid return.
Any idea how I trap this?
Thanks
Everso
Selecting Row In Listview
I have a listview with about 200 items, I know i can select say item 15 with
Code:
Lv.SelectedItem = lv.ListItems(15)
but the srollbar does not follow, is it possible to fix that?
Thanks : )
Selecting Nothing In A Listview
I'm trying to make a simple copy of the Windows explorer (just the look-and-feel) to put in my project. The look is there and so is most of the feel but there is one small thing I just can't seem to figure out.
When you use Explorer and select items (files and folders) the items in the explorer bar(change name, copy file, move file, ...) on the left of the screen change. When you click on a white space they also change and you get other options to add a folder etc.
What I got working is the changing items when the user clicks a folder or a file. But somehow I just can't select nothing in the listview component. If I click on a white space in the control the last Listitem gets selected. But I want nothing to be selected so I can display the add folder items etc.
any suggestions ob how to do this?? probebly some kind of function that checks if a listitem is under the mouse position or something, but I don't know to implement this
thx in advance
ListView Selecting?
I have a ListView being populated by a datacontrol on the same form. Let me post that code first, in case i am starting this proccess all wrong to begin with :
VB Code:
ListView1.View = lvwReportDim strQueryString As StringDim i As Integer With ListView1.ColumnHeaders .Add , , "FName" .Add , , "LName" .Add , , "Address"End With varBookmark = datFind.Recordset.BookmarkstrQueryString = ("[State]= '" & Text7.Text & "'") datFind.Recordset.FindFirst strQueryStringi = 0Do Until datFind.Recordset.NoMatchi = i + 1 ListView1.ListItems.Add , , datFind.Recordset("FirstName") ListView1.ListItems(i).SubItems(1) = datFind.Recordset("LastName") ListView1.ListItems(i).SubItems(2) = datFind.Recordset("Address1") datFind.Recordset.FindNext strQueryStringLoop
So now that i have the ListView populated i want to click on a row and have it take me to a new form with the specific data from that record. My issue is how to make the ListView so that i knows, when i click on "John Doe" that it needs to pull that record from the table so that i can populate the textboxes on the next form. This is how i did it with a DBList :
VB Code:
Private Sub DBList1_Click()Const strAstApos As String = "*'"Const strAposAst As String = "'*"Dim strSQL As StringDim varClient As VariantvarClient = DBList1.SelectedItemdatFind.Recordset.Bookmark = varClient Form1.txtClientName.Text = datFind.Recordset("FirstName") & " "& _ datFind.Recordset("LastName")Form1.txtAddress.Text = datFind.Recordset("Address1")Form1.txtCity.Text = datFind.Recordset("City")Form1.txtState.Text = datFind.Recordset("State")Form1.txtZip.Text = datFind.Recordset("zipcode")Form1.txtHomePhone.Text = datFind.Recordset("PhoneNumber")Form1.txtEmail.Text = datFind.Recordset("Email") Form4.HideForm1.Show
but i cant quite get it to accomplish the same thing with a ListView.
The bottom line is that when i select a row from the ListView, i want to be able to reference the record that the data came from.
Any suggestions would be MUCH appriciated ... thanks for the help guys !!
Selecting Listview
Hi, I have a few problems with listview:
1) I want to select an item in the listview which later I need to remove an amount of the item from the listview. Let's say I selected Raw Material with an amount of 200. I click "Remove" button and remove 100 unit from the Raw Material. How do I actually do this?
2) I notice that when I select the item in the listview, it allows me to rename the item. What can I do to prevent the user from doing the same thing?
Please help. Thanks
Selecting In Listview
hi,
I have a explorer like program with a listview for viewing the files. I just wondered how i could select a file in the listview without clicking.
For example, I push a button and listview will select file number 3 from top, is it possible at all?
thanks
Selecting The First Row In A Listview
Hi,
Can anyone help me with the following. I have a listview control. After adding some rows I want to select the first row. The code I'm using is as follows:
Code:
If lvwSearchResults.ListItems.Count > 0 Then
Set lvwSearchResults.SelectedItem = lvwSearchResults.ListItems(1)
'lvwSearchResults.SetFocus
'lvwSearchResults.ListItems(1).Selected = True
'lvwSearchResults.Refresh
End If
I've also tried any number of variations with the commented lines of code, but none of them work. Any idea what I'm doing wrong?
Thanks very much,
dlarkin77
Selecting Listview
Hi ALL
I have some data in a listview.
I have a command button.
how can select all items in the listview by clicking the button.
I have selected all items by pushing down shift key.
but i want to do the same thing with a single click.
kind regards
elias
Selecting A Row In Listview
Greetings,
I'm currently developing a program which uses a listview to display a recordset.
I want the user to be able to search for a specific string (no problem) and select the according tekst in the listview (big problem).
Any ideas??
Thanks,
Patrick
ListView Selecting An Item
Dear friends
I'm using ListView control, but I'm having problems to select/focus an datermined cell in the grid.
For example, I click in the second cell in the third line, nut thw focus alway happen to the first cell of the third line.
How I do to select/focus the cell that the user clicks?
Thanks and sorry about my bad english.
Selecting Subitems In A Listview
I want to make the program select an item of a listview when you click on one of it's subitems/columns. Does anyone know of a good way to do this?
Thx.
Selecting Listview Items
I am having trouble moving to the next item in a listview automatically. I am trying to create option buttons and put the text from the listview to the option button to have users select with Name they want. I do not know how to select the next item below or above the selected item in the listview? Any sugestions? Thanks
Selecting Values That Are Not On The Listview
This is my sample code
Code:
...
rsSubjects.Open "Select * From LoadSectionSubjects Where Courses.Title=
'" & txtCourse.Text & "' And Sections.Title='" & txtSection.Text & "'
And " & "Semester='" & txtSemester.Text & "' Order by SubjectCode ASC", dbConnection, 1, 1
Dim i As Long
While Not rsSubjects.EOF
For i = 1 To lvwCourses.ListItems.Count
'The subject column is on the subitems 2 of the listview
If rsSubjects!SubjectCode<>lvwCourses.ListItems.Item(i).SubItems(2)
cboSubjectCode.AddItem rsSubjects!SubjectCode
End If
rsSubjects.MoveNext
Next i
Wend
...
Please guide me
Selecting Listview Items
Hi, am working on a movie check-in form. This form displays all movies that have been checked out by a particular customer. The Listview control is populated by selecting the customerID from the cboCutomers control. Assuming that a customer has three movies checked out but instead of returning/checking in all the 3 movies, he wants to return only on of the moves listed. How can I ensure that the selected movie is the one that is checked out when I click on the check-in command button?
Thanks
ListView, Selecting Via Code?
After I fill my listview control, I want to automatically select the first entry, which I do via:
Code:
lstRoster.ListItems.Item(1).Selected = True
Call lstRoster_ItemClick(lstRoster.ListItems.Item(1))
but the item isn't actually selected, how do I do that?
Selecting An Item From A ListView
Here is what MSDN says to do to select an item from a listview:
"
To programmatically select a ListItem object, use the Set statement with the SelectedItem property, as follows:
Set ListView1.SelectedItem = ListView1.ListItems(1)
"
I cannot seem to get it to work. Is there a property that I need to set or I have set wrong?
Here is a simple example that I am trying to get to work without any luck:
Private Sub Command1_Click()
Set lstView1.SelectedItem = lstView1.ListItems(1)
End Sub
I cannot get this to do anything.
Any ideas??
Finding (*and Selecting*) A Listview
I've set up a listview in my project, and a command button which opens a seperate form with a "find" box on it.
When the user clicks the "find now" button on the second form, I do a FINDFIRST on the recordset of the listview control, and now I want to close this window and highlight the "found" record on the listview.
I tried setting the key of each list subitem when I was adding them by
sCurJob = Format(CStr(myRs!jobid), "000000")
Set itmX = ListView1.ListItems.Add(n, sCurJob, sCurJob)
and then just use
Set frmAllList.ListView1.SelectedItem = _
frmAllList.ListView1.ListItems(sNum)
where sNum is the "jobid" field of the found record, but I keep getting "Invalid Key" on the Add method.
Scrapping this (temporarily), I tried the .FindItem method, but this only seems to work satisfactorily for the main item, and not the subitems, even though I set the 'value setting' to 1 (for lvwSubitem).
Has anybody any experience of this kind of thing, and how did they handle it? (Better than these clumsy tries, I bet!)
Ta.
Selecting Listview Record
I have a listview which i want to select the first record by code so i did as following:
lvwMDI(0).ListItems.Item(1).EnsureVisible
lvwMDI(0).ListItems.Item(1).Selected = True
by the code above the first line is selected but not highlighted. i want the first be highlighted, what should i do?
Selecting Items In ListView
I have a ListView control called Lista in Report mode, and I want to select the first item in the list.
First I populate the list with
Lista.ListItems.Add , , mytext
then I select the first item with this code that I've found in MSDN:
set Lista.SelectedItem = Lista.ListItems(1)
The list is correctly populated, but nothing is selected.
Where am I wrong?
Selecting Rows In A Listview
I want to be able to select each row in a listview and display them one at a time. Here's a sample of the code
ItemNum = Lv1.ListItems.Count ' This could be more than 1
for inum = 1 to ItemNum
strEvent = Lv1.ListItems.Item(inum)
Lv1.SelectedItem = strEvent
for num = 1 to 4
txtEventInfo.Item(num).Text = Lv1.SelectedItem.SubItems(num)
next num
ItemOne = txtEventInfo.Item(1).Text
ItemTwo = txtEventInfo.Item(2).Text
ItemThree = txtEventInfo.Item(3).Text
ItemFour = txtEventInfo.Item(4).Text
next inum
I can print out row one with all the items but I can't get to row two.
Any help would be appreciated.
Mike@work
Programmatically Selecting Listview Items In VBA
Is there any way to programmatically select an item is a Listview in Microsoft Access? I know you can do it in VB6 using the set listview1.selecteditem = listview1.listitems(x) command, but I cannot find the correct property in the VBA version of the control.
Thanks, Evan
Selecting Sub Items Of A ListView Control
Hi guys, in my listview control i need to be able to select any subitem and be able to double click it to edit the text in it. I have searched everywhere and i have found no answers, does anyone know to to do this?
Selecting/De-select All Items In A ListView
On my form that has the ListView control, I have two command buttons, cmdAll and cmdNone. When you click on cmdAll it should check all the items in the Listview and when you click on cmdNone, it should de-select all checked items. how can I ensure that? My present code for checking items is:
VB Code:
Dim i As Long For i = 1 To ListView1.ListItems.Count If ListView1.ListItems.Item(i).Checked = True Then frmMovie.lstAudio.AddItem ListView1.ListItems.Item(i).Text End IfNext
Thanks
ListView Selecting Second Colum Info
Ok i got the adding and removing part of the listview along with some other stuff. Now how do i add text to a text box when i click on 1. LIke i have 2 colums like this
and i want to be able to either click on the text under the File Colum and then the text uner the File Path Colum goes to like a textbox. You get it ? If not tell me ok.
Automatically Selecting An Item In ListView VB6
I've just changed over a set of information I had from a tabbed listbox to a listview because of it's ease of resizing use etc. However - I need to be able to automatically highlight an item in the list from the code. I used to be able to do this in the listbox just by the Obj.ListIndex = [number] syntax - but I can't find the property to do it. Here's what I'm doing to clear all of the selected ones in the ListView and then setting the one I want :
Public Sub SelectItem(Item As Integer)
If Item < -1 Then Item = -1
If DiaryList.ListItems.Count <> 0 Then
For a = 1 To DiaryList.ListItems.Count
DiaryList.ListItems(a).Selected = False
Next a
If Item <> -1 Then DiaryList.ListItems(Item).Selected = True
End If
End Sub
Obviously what i'm doing here is if I want to clear all Items from being Selected I call the Sub with -1 - however if I call it with an integer - I want it to clear all the others and highlight THAT item. This sets the properties right - I've checked in the Watch - but unfortunately does not show the item as being highlighted/selected in the on screen ListView. I've even tried calling DiaryList.Refresh at the end of the sub to no avail.
Any ideas?
Thanks
Adam Hourigan
Programmatically Selecting Listview Items In VBA
Is there any way to programmatically select an item is a Listview in Microsoft Access? I know you can do it in VB6 using the set listview1.selecteditem = listview1.listitems(x) command, but I cannot find the correct property in the VBA version of the control.
Thanks, Evan
Selecting Items And Getting BackColor In An External ListView
This is a tall order, and I would not be asking if there was no other way. I downloaded this great code that did exactly what I wanted(Dr. Memory's External ListView example). Well I didn't realize that I needed one more thing I need to select and item on the external ListView the same item I have selected on my ListView.
i.e.
If I select index number 1 on my list the program would need to select index number 1 on the external list.
I looked for the opposite of LVM_GETITEM but it is LVM_SETITEM and I don't want to change the items text just select it. It would be nice if there was something like LVM_SELITEM
I searched the best i know how to for an example on how to do this, but to no avail.
Thank you vary much,
James
P.S. It is not as important but I would like to know how to get the item's back ground color.
Problem Selecting First Item Of External Listview
Hi all i got this code that supposed to select and highlight the first item of external list view but unfortuntly when i click the command button it does not do any thing. It seems it can not find the right window . i placed the class name of external listview and caption of the window that holds the listview but no luck. i be happy if an expert tell me how to fix this.Thanks
Code:
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Function VirtualFreeEx Lib "kernel32" (ByVal hProcess As Long, lpAddress As Any, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Type LV_ITEM
mask As Long
iItem As Long
iSubitem As Long
state As Long
stateMask As Long
pszText As String
cchTextMax As Long
iImage As Long
lParam As Long
iIndent As Long
End Type
Private Const LVM_FIRST = &H1000&
Private Const LVM_SETITEMSTATE = (LVM_FIRST + 43)
Private Const LVIF_STATE = &H8&
Private Const LVIS_FOCUSED = &H1
Private Const LVIS_SELECTED = &H2&
Private Const PROCESS_VM_OPERATION = &H8
Private Const PROCESS_VM_READ = &H10
Private Const PROCESS_VM_WRITE = &H20
Private Const PAGE_READWRITE = &H4&
Private Const MEM_RESERVE = &H2000
Private Const MEM_COMMIT = &H1000
Private Const MEM_RELEASE = &H8000
Private hWndlvw As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Private Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As String) As Long
Dim strCaption As String
Dim lLen As Long
hWndlvw = FindWindowEx(hWnd, 0&, "SysListView32", "")
' If we've found a window with the SysListView32 class
' check to see if parent window caption is the one we are looking for
If hWndlvw <> 0 Then
lLen = GetWindowTextLength(hWnd)
If lLen > 0 Then
strCaption = Space(lLen)
GetWindowText hWnd, strCaption, lLen + 1
End If
End If
EnumWindowsProc = (hWndlvw = 0 And strCaption <> lParam)
End Function
' New example looks for a window with class SysListView32 that is hosted
' by a window whose caption matches the contents of strInWindowWithCaption
Public Function FindListView(strInWindowWithCaption As String) As Long
EnumWindows AddressOf EnumWindowsProc, StrPtr(strInWindowWithCaption)
FindListView = hWndlvw
End Function
Public Function MessageCrossProcess(ByVal hWnd As Long)
Dim lProcID As Long
Dim hProc As Long
Dim lxprocLVITEM As Long
Dim LVITEM As LV_ITEM
Dim lItemPos As Long
GetWindowThreadProcessId hWnd, lProcID ' Get the process ID in which the ListView is running
If lProcID <> 0 Then
hProc = OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_VM_WRITE, False, lProcID) ' make sure we have read write permissions in the process space
If hProc <> 0 Then
lxprocLVITEM = VirtualAllocEx(hProc, 0, LenB(LVITEM), MEM_RESERVE Or MEM_COMMIT, PAGE_READWRITE) ' Grab enough memory in the other procedure's space to hold our LV_ITEM
' Set up our local LV_ITEM to change the selected item
LVITEM.mask = LVIF_STATE
LVITEM.state = True
LVITEM.stateMask = LVIS_SELECTED Or LVIS_FOCUSED ' Just enforcing the selection better than in original version by moving the focus as well
' Copy the local LV_ITEM into the space we reserved in the foreign process
WriteProcessMemory hProc, ByVal lxprocLVITEM, ByVal VarPtr(LVITEM), LenB(LVITEM), 0
' Now send the message, but pass the address of the copy of our LV_ITEM that now exists in the foreign process instead of our local version
lItemPos = 0& ' first item
SendMessage hWnd, LVM_SETITEMSTATE, lItemPos, ByVal lxprocLVITEM
' Clean up
VirtualFreeEx hProc, ByVal lxprocLVITEM, LenB(LVITEM), MEM_RELEASE
CloseHandle hProc
End If
End If
End Function
and the on click event
Code:
Private Sub Command1_Click()
MessageCrossProcess FindListView("Rooms List - Search Results")
End Sub
Selecting A Record In A Listview Using The 'text' Property
I'm trying to select (highlight) a listview record in code using the first value in the listview record (text property) instead of the index value.
it seems like it should be something like this:
dim theid as string
lstvw.itemdata.selected = theid
this sets the value of the current selected record to the value of theid instead of selecting the value that corresponds to the theid value.
Any input would be appreciated.
ListView: Selecting Item Baised On .text
with the ListView, report mode
I want to do
VB Code:
listview.listitem(x).selected= true
based on a certain item.text string
is there a way to specify the item index using the string text?
I know what all the texts will be, but not the order.
(or do I have to scan all item's text for a match? yawn!)
Multiple Selections & Selecting A Subitem In ListView
Hello All-
I am a first time user of Visual Basic. I am trying to use a List View control. I have two questions.
- I am wondering if it is possible to allow the user to select and edit a subitem. If it is possible I would very much appreciate any help or sample code on how to accomplish this.
- My second question deals with allowing multiple selections in a List View. I need to go through all the user selected items within the List View. I know that I could go through each item and check to see if it is selected, but there must be a better way. Is there a way to get the total amount of items selected, or even better a list of all the indexes that are selected?
Any help or guidance is greatly appreciated.
ListView - Selecting First Item In List Causes Rename
I have an application with several Listview controls on it, in report view containing a few columns of data.
The application requires selecting some items in the ListView and adding them to another Listview.
My problem is that when the first item in the ListView is selected (only for the first item) It tries to let you rename the item, rather than merely selecting it.
Does anyone know if there is a way to stop this from happening?????
ListView Questions
I am currently using a listview to display the results of a query.
One of the fields in the query is a memo type, and contain newline characters. The listview is failing to show this properly.
Is there anyway to make a listView display multiple lines, or is it only designed to display a single line.
If the listView can not do what I want, what other controls can I use.
I don't really want to use a flexgrid, and I want to have a hidden Key Value that I can get from clicking on the row, and I also need to have the ability to sort fast by clicking on a column header. I dont think that the FlexGrid will give me this functionality.
Listview Questions
1. How do I preserv the colors I've made in a listview control? Because it seems all the forecolors i've changed in get erased when I add an item.
2. How do I get it to remember how far down it was scrolled when I refresh the listview?
Listview Questions...
Ok, I've got a listview control on a form.
I add amongst other things dates in one column of the listview.
Is there a way that these dates are sorted from the newest to oldest.
Right now when I'm trying to sort them the are sorted alphabetically.
e.g.
01/04/2001
.
.
.
.
02/04/2001
the correct should be
02/04/2001
.
.
.
.
01/04/2001
Thanks
ListView Questions
how can i add a vertical scrollbar to a listview?
also, when i have multiselect on, how can i have a command remove all selected items from the listview
this is the code i am currently using
Code:
If Not ListView1.SelectedItem Is Nothing Then
If ListView1.SelectedItem.Selected = True Then
ListView1.ListItems.Remove (ListView1.SelectedItem.Index)
End If
End If
also, how can i "Select All" in a ListView
-ThX
ListView Questions
Hi,
Some ListView control questions:
How do I (at runtime) -
1. Set the row's (ListItem) height ?
2. Set the column header's height?
3. Align-center the column header's text?
4. Set the column header's text color?
Thanks!
Some Questions About ListView
I'm quite new to ListView control so I have some questions about ListView and I hope that someone can help me.
I'm using IvwReport view mode and have two columns on ListView.
1. Question:
To add some data to first column I'm using this code:
Code:
ListView1.ListItems.Add = "Some Text"
How can I add some data to second column ?
2. Question:
How can I erase all data from all columns ?
ListView Questions
Using VB 6 and MS Access
I have a ListView populated with data from a MS Access Database Table.
I have a Command Button which (when clicked) populates various text boxes with additional data from the ListView.SelectedItem (Recordset).
My problems:
1. If the ListView is empty (no data in the table) and the user still presses the Command Button... how do I avoid errors?
2. If the ListView contains data, but the user doesn't "select" a record... the Command Button action assumes the ListView.SelectedItem is the First Record. Is there a way to specify that "No" Records are selected?
I would rather show a Message Box stating "Please select a record" rather than the program defaulting to the first record.
I hope this makes sense! Any suggestions are GREATLY appreciated!!!
|