By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,400 Members | 1,021 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,400 IT Pros & Developers. It's quick & easy.

How to set un-editable column in Listview?

P: 48
Hello,

I have a Listview control which displays various data.
The default selected item is the first item.
(Is it always the first item?)

Here's a simple code:
Expand|Select|Wrap|Line Numbers
  1.     Dim objListItem As Object
  2.  
  3.     lstvwXclList.View = lvwReport
  4.     ' Set column headers 
  5.     With lstvwXclList.ColumnHeaders
  6.         .Add , , "Activity", 4000
  7.         .Add , , "Description", 4700, lvwColumnLeft
  8.         .Add , , "Filename", 2400, lvwColumnRight
  9.     End With
  10.  
  11.     Set objListItem = lstvwXclList.ListItems.Add()
  12.     objListItem.Text = "Swimming"
  13.     objListItem.SubItems(1) = "400 m Freestyle"
  14.     objListItem.SubItems(2) = "Swimming.xls"
The only clickable column is the first column.
In this case, the "Activity" column.

The problem here is the data in "Activity" column is editable.
The data need not to be edited. It must stay as is.

What to do in order to set it un-editable?
Haven't found any settings in the control's properties.

Help from the experts and the knowledgable are greatly appreciated.
Sep 30 '08 #1
Share this Question
Share on Google+
10 Replies


NeoPa
Expert Mod 15k+
P: 31,661
What types of objects are you using? A ListBox control on a Form?
Sep 30 '08 #2

ADezii
Expert 5K+
P: 8,669
Juast subscribing for now. Is all the data for the ListView Control going to be Manually or Dynamically added, and if Dynamically, what is the Data Source?
Sep 30 '08 #3

NeoPa
Expert Mod 15k+
P: 31,661
Right, so there is a ListView control available. I found it after hunting through the Additional Controls list. This would be found on a Form object for anyone who is not familiar with all the various objects available within Additional Controls.

As this is not something I'm familiar with I will simply watch with interest.
Sep 30 '08 #4

ADezii
Expert 5K+
P: 8,669
I took the liberty of revising your code, which should now work as originally intended. Let me know how you make out:
Expand|Select|Wrap|Line Numbers
  1. Dim itmX As ListItem
  2.  
  3. 'Make sure ListView control is in report view.
  4. Me![lstvwXclList].View = lvwReport
  5.  
  6. With Me![lstvwXclList]
  7.   'Add three columns (index, key, text, width, alignment, icon)
  8.   .ColumnHeaders.Add , "Activity", "Activity", 4000, lvwColumnLeft
  9.   .ColumnHeaders.Add , "Description", "Description", 4700, lvwColumnLeft
  10.   .ColumnHeaders.Add , "Filename", "Filename", 2400, lvwColumnRight
  11. End With
  12.  
  13. 'Add Activitys to column 1 (index, key, text, icon, smallicon)
  14. Set itmX = Me![lstvwXclList].ListItems.Add(1, "Swimming", "Swimming")   'C1R1
  15. ' Use the SubItemIndex to associate the SubItem with the correct
  16. ' ColumnHeader. Use the key ("Description") to specify the right
  17. ' ColumnHeader.
  18. itmX.SubItems(Me![lstvwXclList].ColumnHeaders("Description").SubItemIndex) _
  19. = "400 m Freestyle"
  20. ' Use the ColumnHeader key to associate the SubItems string
  21. ' with the correct ColumnHeader.
  22. itmX.SubItems(Me![lstvwXclList].ColumnHeaders("Filename").SubItemIndex) _
  23. = "Swimming.xls"
  24.  
  25. 'User cannot Edit Labels
  26. Me![lstvwXclList].LabelEdit = lvwManual
P.S. - If you so desire, I can also Attach the Test Database used for this Thread, just let me know.
Sep 30 '08 #5

P: 48
I took the liberty of revising your code, which should now work as originally intended. Let me know how you make out:
Expand|Select|Wrap|Line Numbers
  1. Dim itmX As ListItem
  2.  
  3. 'Make sure ListView control is in report view.
  4. Me![lstvwXclList].View = lvwReport
  5.  
  6. With Me![lstvwXclList]
  7.   'Add three columns (index, key, text, width, alignment, icon)
  8.   .ColumnHeaders.Add , "Activity", "Activity", 4000, lvwColumnLeft
  9.   .ColumnHeaders.Add , "Description", "Description", 4700, lvwColumnLeft
  10.   .ColumnHeaders.Add , "Filename", "Filename", 2400, lvwColumnRight
  11. End With
  12.  
  13. 'Add Activitys to column 1 (index, key, text, icon, smallicon)
  14. Set itmX = Me![lstvwXclList].ListItems.Add(1, "Swimming", "Swimming")   'C1R1
  15. ' Use the SubItemIndex to associate the SubItem with the correct
  16. ' ColumnHeader. Use the key ("Description") to specify the right
  17. ' ColumnHeader.
  18. itmX.SubItems(Me![lstvwXclList].ColumnHeaders("Description").SubItemIndex) _
  19. = "400 m Freestyle"
  20. ' Use the ColumnHeader key to associate the SubItems string
  21. ' with the correct ColumnHeader.
  22. itmX.SubItems(Me![lstvwXclList].ColumnHeaders("Filename").SubItemIndex) _
  23. = "Swimming.xls"
  24.  
  25. 'User cannot Edit Labels
  26. Me![lstvwXclList].LabelEdit = lvwManual
P.S. - If you so desire, I can also Attach the Test Database used for this Thread, just let me know.
Sorry...it took me so long to reply.

This is what makes it work:

Me![lstvwXclList].LabelEdit = lvwManual

Now, it is un-editable. =)

Changing the LabelEdit property in VB Editor seems
to be not working. No matter what value I set, it always
reverts to its original value. (Could it be a bug?)

Anyway, this issue is considered SOLVED.

Thanks to NeoPa and ADezii!
(...for their time and effort)

You both did help another one here. =D
Oct 1 '08 #6

P: 48
....

Changing the LabelEdit property in VB Editor seems
to be not working. No matter what value I set, it always
reverts to its original value. (Could it be a bug?)

....
I now know why setting the properties of ListView control in
VB Editor doesn't work. It is because the ListView has its own
"Property" setting.

The pre-defined Property Setting link is the "Properties".
But the ListView's link is "ListViewCtrl Object".
Please refer to attached image.



No wonder why my settings were not reflected.

Weirdness of the ListView Property Setting solved.

(Signing off)
Oct 1 '08 #7

ADezii
Expert 5K+
P: 8,669
I now know why setting the properties of ListView control in
VB Editor doesn't work. It is because the ListView has its own
"Property" setting.

The pre-defined Property Setting link is the "Properties".
But the ListView's link is "ListViewCtrl Object".
Please refer to attached image.



No wonder why my settings were not reflected.

Weirdness of the ListView Property Setting solved.

(Signing off)
ListViewCtrl is the ActiveX Control's OLE Class Name, you should still be able to modify the LabelEdit Property programmatically in the manner in which I have described, and what I have been successful doing. Oh well, as long as it works it will have to remain a mystery - ActiveX Controls are funny that way! (LOL)!
Oct 1 '08 #8

NeoPa
Expert Mod 15k+
P: 31,661
Keirnus, you're welcome to what little assistance I was able to provide on this one.

May I also say that we appreciate your updating the thread with your new understanding of the matter. I expect this will be quite useful for those coming after us :)
Oct 1 '08 #9

P: 48
ListViewCtrl is the ActiveX Control's OLE Class Name, you should still be able to modify the LabelEdit Property programmatically in the manner in which I have described, and what I have been successful doing. Oh well, as long as it works it will have to remain a mystery - ActiveX Controls are funny that way! (LOL)!
Yes, it can be modified programatically.
It is what I am implementing now.
That's to make sure it has the right property setting
even if somebody's gonna change it in VB Editor.
Oct 3 '08 #10

ADezii
Expert 5K+
P: 8,669
Yes, it can be modified programatically.
It is what I am implementing now.
That's to make sure it has the right property setting
even if somebody's gonna change it in VB Editor.
You can also Password Protect the code in the VB Editor Window if you so desire.
Oct 3 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.