[RESOLVED] Access DataBase and ListBox
Hi!!! :wave:
I've a Access Database called DK Items.mdb , in the database i've this table: http://img123.imageshack.us/img123/5991/tabela5ii.jpg
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!!!!!!!!
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:
Dim items(myDataTable.Rows.Count - 1) As String
Dim row As DataRow
For i As Integer = 0 To items.GetUpperBound(0) Step 1
row = myDataTable.Rows(i)
items(i) = String.Format("{0} {1} {2} {3} {4} {5} {6} - {7}", _
row("category"), _
row("number"), _
row("level"), _
row("durability"), _
row("skill"), _
row("luck"), _
row("options"), _
row("name"))
Next row
myListBox.Items.AddRange(items)
'OR
'myListBox.DataSource = items
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!!
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.
Re: Access DataBase and ListBox
Lol I'm using .Net 2.0, and data is readwrite.
Thks again.
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 ...