Results 1 to 6 of 6

Thread: [RESOLVED] Access DataBase and ListBox

  1. #1

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Resolved [RESOLVED] Access DataBase and ListBox

    Hi!!!

    I've a Access Database called DK Items.mdb , in the database i've this table:

    I want for each row of data to add to a listbox the data by the following order category, a space, number, a space, level, a space, durability, a space, skill, a space, luck, a space, options, the text " - " and for last the name. (The altura and largura i dont want to display in the listbox).
    Another question:how can i add data to the table i want inside my database in the colunn i want (sry for my horrible english).

    Thks a lot!!!!!!!!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Access DataBase and ListBox

    Using a ListBox for tabular data is generally a bad idea. Normally you should use either a ListView in Details view or a grid (DataGrid or DataGridView) because they all provide columns. If you're determined to use a ListBox then the easiest way to create each string would be with the String.Format method:
    VB Code:
    1. Dim items(myDataTable.Rows.Count - 1) As String
    2. Dim row As DataRow
    3.  
    4. For i As Integer = 0 To items.GetUpperBound(0) Step 1
    5.     row = myDataTable.Rows(i)
    6.     items(i) = String.Format("{0} {1} {2} {3} {4} {5} {6} - {7}", _
    7.                              row("category"), _
    8.                              row("number"), _
    9.                              row("level"), _
    10.                              row("durability"), _
    11.                              row("skill"), _
    12.                              row("luck"), _
    13.                              row("options"), _
    14.                              row("name"))
    15. Next row
    16.  
    17. myListBox.Items.AddRange(items)
    18. 'OR
    19. 'myListBox.DataSource = items
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Re: Access DataBase and ListBox

    Thks!!! Again

    If u thing that with datagrid is better could u post the code pls, it will realy help.

    Thks!!

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Access DataBase and ListBox

    If you're using .NET 1.1 and the data is read-only or you want to edit a row at a time is a separate form then I'd tend to use a ListView. If you are using .NET 1.1 and you want in-place editing then I'd tend to use a DataGrid. If you're using .NET 2.0 then I'd tend to use a DataGridView.

    With both grids it's just a matter of assigning your table to the DataSource property. You can also use the ExtendedListView from the WFC library in my signature and bind to it the same way, or use the standard ListView and add your items manually.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Re: Access DataBase and ListBox

    Lol I'm using .Net 2.0, and data is readwrite.

    Thks again.

  6. #6

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Re: Access DataBase and ListBox

    Forget what i said earlier. Now i've another question:
    I've the dataset called DkItems and i've a table Dk_Armors, now i've a form that when u click a button he should add a new row to the file with the database Dk Items with the values chosen from others controls (text box) but i cant add a new item to the Database: for exemple to the colunn "name" add from textbox1.text, colunn "category" add from textbox2.text ...

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