|
-
May 9th, 2009, 11:45 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Split the string by three and display on the listbox
Hello everyone, I have a problems regarding on how to display my data by 3 characters every listbox. This what really my problem is, I have data coming from my database and that specific field contains numbers but the problem is that is was merge and what i want is that i want to split that by 3 so that i can get the itemcode coming from other table that i need to display again on my grid or listbox. This is how it look like.
Ex. Data from my MS Access:
Code:
First Table
Pojectcode ItemName
123456789 Potato Chips
Second Table:
ItemCode BrandName
123 Mr.Chips
456 Lays
789 Cheetoos
by calling that project code how can i split that string into three? And how can i display that will look like the second table but display on listbox? Thanks in advance guys.
Last edited by shyguyjeff; May 11th, 2009 at 02:10 AM.
-
May 10th, 2009, 04:08 AM
#2
Re: Split the string by three and display on the listbox
You really need to use a listview if you want mulitple columns - create a listview, set its view property to "Details" and set up two columns in its "columns" collection.
Then you'd have code something like this :
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myString As String = "ABCDEFGHIJKL"
Dim myItem As ListViewItem
For z As Integer = 0 To myString.Length - 1 Step 3
myItem = ListView1.Items.Add(myString.Substring(z, 3))
myItem.SubItems.Add("Brandname here")
Next
End Sub
End Class
The substring method of a string (in this case) takes two arguments - the start position (z) and the length of the string you want (3). Making the loop use Step 3 means that the counter will go up in jumps of 3 instead of 1, ie z will be 0, 3, 6 and 9 and get chunks of three characters each time.
When adding data to columns within a listview item you need to first add the item to the listview (which will set the text for the first column) and then do SubItems.Add to add text for each subsequent column.
Note - you would also first want to check that the length of the string is a multiple of 3 otherwise there will be an exception thrown.
Last edited by keystone_paul; May 10th, 2009 at 04:11 AM.
-
May 10th, 2009, 05:19 AM
#3
Thread Starter
Hyperactive Member
Re: Split the string by three and display on the listbox
Thank you keystone_paul now i have an idea. But i forgot to mention i will used it on asp.net is there any function that will act like a listview on asp.net. Sorry maybe i posted in a wrong section, I was thinking that i am developing using windows application but sad to say i am developing using web forms but anyway i think they have the same concept on asp.net but the main thing is that what tool should i used instead of listview? Again thank you very much keystone_paul. Have a nice day.
-
May 10th, 2009, 05:30 AM
#4
Re: Split the string by three and display on the listbox
Personally I'd just create an HTML table unless you need it to scroll (ie you want it to have a set size on the page and allow the user to scroll to rows further down rather than have the table expand to accomodate all the rows).
If you are developing for the web though you need to consider the usability of your page if you are going to load hundreds of records - due to the performance lag of sending the data over the internet you would be better off adopting a "page at a time" approach - in which case a table would be fine.
-
May 10th, 2009, 06:59 AM
#5
Thread Starter
Hyperactive Member
Re: Split the string by three and display on the listbox
Ahhh i see... I am just new upon developing a web so i am not too much familiar of it. I was thinking if it is possible to load it on the grid and view as what i want? Or what will be your suggestion in solving my problem?
-
May 10th, 2009, 07:24 AM
#6
Re: Split the string by three and display on the listbox
Personally I would just write the code in my ASP page to accept a page number as a parameter and extract just the number of records I need and generate an HTML table with those rows, and hyperlinks to the first page, next page, previous page and last page as appropriate.
I dare say some of the newer web controls would do a lot of that for you automatically but I'm old fashioned and prefer to write the code myself rather than use data binding!
I'm sure you'll be able to get some better advice about grids etc over on the asp.net forum.
-
May 11th, 2009, 12:46 AM
#7
Thread Starter
Hyperactive Member
Re: Split the string by three and display on the listbox
ok thanks keystone_paul... Have a nice day and God Bless.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|