CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Write contains of listbox

    How can I write contains of 3 listboxes into 1 file without replacing each other's data. I can't write it to specific line, because listbox contains could be modified by user, it could be only one line in listbox, but it could be 20, so I need to get last line that was written by listbox 1, then write listbox 2 and before writting listbox 3, get last line that was written by listbox 2....how????


  2. #2
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Re: Write contains of listbox

    Oh, then I need to read all that saved data into appropriate listbox when form is loaded


  3. #3
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Write contains of listbox

    A quick (and easy) way would be to use an INI file (GetPrivateProfileString etc API's).

    You could then have sections such as :

    [List1]
    NumListItems=5
    ListItem1=blah
    ListItem2=Blah

    etc

    [List2]
    NumListItems=2
    ListItem1=

    etc

    This way, you can easily get the number of items, the last item and still write them in any order you like.


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  4. #4
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Write contains of listbox

    Or you could use XML - if you have IE5 installed, you can easily parse a simple XML File such as :

    <LISTBOXES>
    <LISTBOX id="1">
    <ITEM>List Item 1</ITEM>
    <ITEM>List Item 1</ITEM>
    <ITEM>List Item 1</ITEM>
    </LISTBOX>
    <LISTBOX id="2">
    <ITEM>List Item 1</ITEM>
    <ITEM>List Item 1</ITEM>
    </LISTBOX>
    </LISTBOXES>

    etc - a good place to learn how to parse this file using the M$ XML parser is http://msdn.microsoft.com/xml


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  5. #5
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Re: Write contains of listbox

    yeah I was thinking about INI, but I was wondering how to get every item from it into listbox, well thanks for advice, I'll try to figure that out



  6. #6
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Write contains of listbox

    If you use the example I posted :

    (using GetPrivateProfileString) :

    1. Get NumListItems from ini file
    2. For x = 1 to NumListItems
    3. Use GetPrivateProfileString for 'ListItem' & x
    4. List1.AddItem that string
    5. Next

    - shouldn't be too difficult - although it means that anyone can edit the file and see how it's structured (and hack it if they feel so inclined)


    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

  7. #7
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Re: Write contains of listbox

    Thanks again. LOL, I don't care if user hack saved file.....it's their problem if he/she will, they'll just have to re-enter all the data back



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