Help with simple program-VBForums
Results 1 to 11 of 11

Thread: Help with simple program

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2013
    Posts
    8

    Question Help with simple program

    I want to create a small app that will allow user to add users to a listbox and create groups for that listbox if desired and all information is kept in database. When the app opens it loads the listbox from the data in the database and seperates it into the users groups if there is any. Can someone please help me with this?

  2. #2
    Frenzied Member
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    2,002

    Re: Help with simple program

    What do you have so far? What is giving you problems?

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2013
    Posts
    8

    Re: Help with simple program

    ok i have figured out that a database really isnt needed and a text file can be used if possible. I just have the add user to list box rihgt now, but I want a way to add groups and assign users to a group, but I cant figure it out for the life of me. I am a very newbie but trying hard.

    Basically I want this:
    Add groups to a listbox:
    Add users to a listbox and have the option to assign any user to any created group:

    The program is set to email anyone that is selected in that listbox and I want it to email everyone in the group if it is selected.

    Any help would be appreciated.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    88,145

    Re: Help with simple program

    While using text files is always an option, if you have multiple sets of related data then a database is probably a better option because they are designed to handle that gracefully. If you really don't want to use a database then I'd suggest at least going with an XML file, which can be saved and loaded directly to a DataSet.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2013
    Posts
    8

    Re: Help with simple program

    Can you give me the code to create groups for users, then be able to save the list and load the list recreating the groups in the listbox? Database is fine also, just thought a text file might be easier.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    88,145

    Re: Help with simple program

    If it was just a list of user names or something like that then a text file would be easier. As you're talking about multiple related entities though, it will be easier to manage using a database, which is built specifically to support such related data. "Easier" is a relative term though. If you don't know how to work with databases in VB.NET then you need to learn that in a general sense first, then apply the appropriate principles to your specific circumstances. You need to first build a database with the appropriate schema and then connect to it from your application in order to work with your data.

    To that end, you should do some reading on ADO.NET. There are various places you could go to do that. One such place is the Database FAQ link in my signature. You could start by creating a database with just a User table and connect to that from your app, adding and editing user records. Once that's working, then it would be time to add the Group table and functionality to link users to groups. There's more to it than just copying a few lines of code and going merrily on your way.

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2013
    Posts
    8

    Re: Help with simple program

    I actually just wanted an example on how to make the listview work. Have any places for that?

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    88,145

    Re: Help with simple program

    A ListView is not the same as a ListBox so the first matter is which you actually want to use. Are you saying that you actually want to use the grouping functionality built into the ListView control?

    2007-2014

    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts) | WP8 Turnstile Feather Transition with Pivot Control
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    New Member
    Join Date
    Jan 2013
    Posts
    8

    Re: Help with simple program

    I want to use the listview control. I want it to look like this:

    User
    Group1:
    User1
    User2
    User
    Group2:
    User1
    User2

    I want a user list with the options to have any user put into a group and I want the program to save all the information and be able to reload it upon next start.

  10. #10
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,241

    Re: Help with simple program

    This is a basic listview load from file routine from which it shouldn't be too difficult to work out the basics of adding/deleting rows and writing the result to a file. It assumes that you will have the correct number of columns and the Groups set up at design time but it would be relatively easy to extend so that these can be set up at runtime from the file. The file is comma separated, with the values followed by the group name, eg.

    B,B1,B2,Alphabet
    1,11,12,Number


    vb.net Code:
    1. Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    2.         ReadFileToLV("C:\TestDir\File1.txt", ListView1)
    3.     End Sub
    4.  
    5.     Private Sub ReadFileToLV(ByVal fName As String, ByVal lView As ListView)
    6.         For Each ln In IO.File.ReadLines(fName)
    7.             Dim SubItem() As String = ln.Split(","c)
    8.             Dim values(SubItem.Length - 2) As String
    9.             For i = 0 To values.Length - 1
    10.                 values(i) = SubItem(i)
    11.             Next
    12.             Dim itm As New ListViewItem(values)
    13.  
    14.             itm.Group = lView.Groups(SubItem(SubItem.Length - 1))
    15.             ListView1.Items.Add(itm)
    16.         Next
    17.     End Sub
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  11. #11

    Thread Starter
    New Member
    Join Date
    Jan 2013
    Posts
    8

    Re: Help with simple program

    I thank you for the post, is there anyway that you can post the same help but with creating the groups at runtime and also by right clicking on the listview and selecting create group?

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.