CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Apr 2009
    Posts
    9

    Need help with ReDim

    Hello! I have this code:

    For i = 1 To Form1.ListView1.ListItems.Count
    Form1.ListView1.ListItems.Item(i).SubItems(1) = 0
    Next

    and the subitems get 0 all time i make a refresh of listview, how can i make a code, that could reserve existing values on subitems and while there is a refresh the existing value doesn't dessapear?

    Thanx

  2. #2
    Join Date
    Jul 2008
    Posts
    70

    Re: Need help with ReDim

    If I understand you correctly, you want to remember what is selected even after a refresh of the listview?

    Why not store what is selected in another datastructure, then after refresh you re-select. So now your truth of what is selected is in your own datastructure and the listview is strictly a view.

    Does that help?

  3. #3
    Join Date
    Apr 2009
    Posts
    9

    Re: Need help with ReDim

    not exactly. all that i want is when listview makes refresh, start counting not from 0 , but from the number which was the latest value of subitem.

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Need help with ReDim

    So instead of 0 you want the subitem to be equal to the last sub item +1 ?

  5. #5
    Join Date
    Apr 2009
    Posts
    9

    Re: Need help with ReDim

    Quote Originally Posted by DataMiser View Post
    So instead of 0 you want the subitem to be equal to the last sub item +1 ?
    yes!

  6. #6
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Need help with ReDim

    Form1.ListView1.ListItems.Item(i).SubItems(1) = Form1.ListView1.ListItems.Item(i).SubItems(1) + 1

    Is this really what you want?

  7. #7
    Join Date
    Apr 2009
    Posts
    9

    Re: Need help with ReDim

    Quote Originally Posted by WoF View Post
    Form1.ListView1.ListItems.Item(i).SubItems(1) = Form1.ListView1.ListItems.Item(i).SubItems(1) + 1

    Is this really what you want?
    i've already done it but the case is that the listview every time make refresh and all subitems disappear, so i need that the Form1.ListView1.ListItems.Item(i).SubItems(1) = Form1.ListView1.ListItems.Item(i).SubItems(1) + 1 work after listview refresh

  8. #8
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Need help with ReDim

    Please explain what you mean by "the ListView makes refresh"

  9. #9
    Join Date
    Apr 2009
    Posts
    9

    Re: Need help with ReDim

    please, watch the code :

    Sub refresh_List()
    Dim a As Integer
    Form1.ListView1.ListItems.Clear
    For a = 1 To frmStatus.ListView1.ListItems.Count

    Form1.ListView1.ListItems.Add , , (form2.ListView1.ListItems(a)), , 1


    Next
    End Sub

    and this is the code that counts items in subitem:

    Form1.ListView1.ListItems.Item(a).SubItems(1) = Form1.ListView1.ListItems.Item(a).SubItems(1) + 1


    and this is the code to give to the subitem the value 0, because, if there is not zero, the Form1.ListView1.ListItems.Item(a).SubItems(1) + 1
    won't work, just won't count. and now

    this is the code to give the 0 value to all subitems:

    For i = 1 To Form1.ListView1.ListItems.Count
    Form1.ListView1.ListItems.Item(i).SubItems(1) = 0
    Next

    so when i call the function "refresh" all existing data get value of 0, so instead of 0 i need the subitem to be equal to the last sub item +1 .

  10. #10
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Need help with ReDim

    Code:
    Form1.ListView1.ListItems.Clear
    Deletes all items from the list view

    You then copy the items from a different list view and set all the subitems=0.

    I really can not tell what you are trying to do here.
    Last edited by DataMiser; April 17th, 2009 at 01:09 PM.

  11. #11
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Need help with ReDim

    Hi !
    Two interesing things
    a) The post has nothing to do with ReDim
    b) Your Refresh has nothing to do with a simple refresh, because refreshing doesn't change any data in a listview

    The question is: What are you realy trying to do. Obviously all of us are wondering about WHAT do you want to achieve.
    My guess is you want to fill the list up to a given amount of data and when you reach a given amount you want to change the data in the list for example if you are scrolling you always want to have a specific amount of data in your list.

    But whatever you do, do a collection in the background where you have all your data and if you want to change that data which are contained in the listview then clear the listview and fill it new with the selected items you will need now. The collection class could be used as your storage.
    Please describe your needs so we can find a god solution for you.
    and please use code tags instead of creating a code jam only. if you dont know how to do reread forum rules. (Or look in the signature of my post )
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  12. #12
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Need help with ReDim

    Quote Originally Posted by dvd212 View Post
    Hello! I have this code:

    For i = 1 To Form1.ListView1.ListItems.Count
    Form1.ListView1.ListItems.Item(i).SubItems(1) = 0
    Next

    and the subitems get 0 all time i make a refresh of listview, how can i make a code, that could reserve existing values on subitems and while there is a refresh the existing value doesn't dessapear?

    Thanx
    This was your first post. Here you are talking about 'Reversing values on subitems' ???? What do you mean with that ?

    Are you talking about a listview wich in the beginning has values like
    Code:
    row (0) subitem(0) = 3,
    row(1)  Subitem (0) =6,
    row(2)  subitem(0) = 12
    and the result should be reversed like 
    row (0) subitem(0) = 12,
    row(1)  Subitem (0) =6,
    row(2)  subitem(0) = 3,
    just top down now like changing sort direction ?
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  13. #13
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Need help with ReDim

    If you want to copy items from another listview you have to take in, that the subitems of the other listview's items are not automatically copied.
    To completely copy an item you have to go:
    Code:
    dim lit as ListItem
    Set lit = Form1.ListView1.ListItems.Add( , , (form2.ListView1.ListItems(a)), , 1)
    For i=1 to Form2.ListView1.ListItems(a).columnheaders.count
          lit.SubItems(i) = Form2.ListView1.ListItems(a).SubItems(i)
    Next
    Now you copy all the subitems from the other ListView, too. Provided, both listviews have the same number of columns.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured