I have a problem where when I add a subitem to the listview all the subitems go out to each of the columns, what I am trying to do is have 4 columns with the results going vertically down each column, I am going to post the code I am using for 1 of the columns so as not to have too much crap on the page here.
Dim source As String = (New Net.WebClient).DownloadString("http://arma.newagerp.com/bb.php")
ListView1.Columns.Add("Deaths")
Dim formula2 As String = "<td><div class='deaths'>([^<]*)</td></div>"
Dim item2 As New ListViewItem("item2", 1)
For Each item As Match In (New Regex(formula2)).Matches(source)
item2.SubItems.Add(item.Groups(1).Value)
Next
ListView1.Items.AddRange(New ListViewItem() {item2})
if you want more code just tell me but this is working and its just the same for the other 3, the other 3 are just player names, score and time in the same listview.
If i undrstand your question right, you want to add next row after passing the value to all four column? if this is right then have a look example code below.
While (Condition)
Dim objItem As ListViewItem
objItem = lv_Details.Items.Add("")
With objItem
.SubItems.Add("")
.SubItems.Add("")
.SubItems.Add("")
.SubItems.Add("")
End With
End While
Hope this will help. :)
Related
I have two listview controls, each having the same column headers. Listview1 contains the master data table and listview2 has a much smaller set of data that I need to add to the Master in Listview1. I can add this new data to the bottom of the main data in Listview1 using the AddRange option, but I need to add it to the top of the data in Listview1 but cannot see how.
If anyone can help I would appreciate it. Thank you in advance.
Thank you for your comments, which I have taken on board.
Let me add some more detail and some code. The data in Listview2 is a monthly csv file input which I read into the Listview2. The data is a set of details with the first field being the date, the most recent date at the top of data. I package this data as an array and attempt to load in into listview1, the master file, with the exact same fields and date order. Here is the code I have used to load the csv and the code to place the packaged data into Listview1. The only problem with this is, it places the data at the end of the current file in Listview1, so it would be out of sequence, so I am trying to place it at the top of the current file in Listview1.
' load the file into listview with this quick routine.
Dim CSVTest As List(Of String) = New List(Of String)
CSVTest = File.ReadAllLines(ImportDirname).ToList
Dim ColNames As List(Of ColumnHeader) = New List(Of ColumnHeader)
Dim ColumnArray() As String = CSVTest(0).Split(",")
For i = 0 To ColumnArray.Count - 1
ColNames.Add(New ColumnHeader)
ColNames(i).Name = ColumnArray(i)
ColNames(i).Text = ColumnArray(i)
Next
ListView2.Columns.AddRange(ColNames.ToArray)
'This adds the rest of the data from the file to the listview.
For I = 1 To CSVTest.Count - 1
Dim col() As String = CSVTest(I).Split(",")
Dim NewLVItem As ListViewItem = New ListViewItem(col(0))
NewLVItem.Name = col(0)
For j = 1 To col.Count - 1
NewLVItem.SubItems.Add(col(j))
Next
ListView2.Items.Add(NewLVItem)
Next (I)
' this adds the range to the bottom of the listview data
' - not what is required. I need it at the top !!!!!
Dim Items(ListView2.Items.Count - 1) As ListViewItem
For i As Integer = 0 To ListView2.Items.Count - 1
Items(i) = CType(ListView2.Items(i).Clone, ListViewItem)
Next
ListView1.Items.AddRange(Items)
Again if anyone can help I would be grateful.
Try Something Like This
With lst1. Items.**Insert**(0, "Sample", 0)
.SubItems.Add(2)
.SubItems.Add(3)
.SubItems.Add(4)
.SubItems.Add(5)
.SubItems.Add(6)
.SubItems.Add(listDownload.Count - 1)
End With
Hope this can help you
I've checked for hours but I can't seem to find anything to help.
I want to loop through tables and columns from a dataset and use the column name in a combobox.items.add() line, however the eventual goal is to fill the combobox from the dataset itself possibly in a combobox.datasource line.
The first problem is that I can't get the code correct to setup the combobox control where it allows me to use .items.add("") and in extension .datasource
Error Message = "Object reference not set to an instance of an object"
dstcopt is the dataset from a oledbDataAdapter .fill(dstcopt,"table") line (which returns correct values)
tc_opt is a tab name on a tab control where the comboboxes are
For Each dstable In dstcopt.Tables
For Each dscolumn In dstable.Columns
Dim colName As String = dscolumn.ToString
MsgBox(colName) 'This retuns "aantigen"
Dim cb As ComboBox = Me.tc_opt.Controls("cb_" & colName)
cb.Items.Add(colName)
'cb_aantigen.DataSource = dstcopt.Tables(dstable.ToString)
'cb_aantigen.DisplayMember = "aantigen"
'cb_atarget.DataSource = dstcopt.Tables(dstable.ToString)
'cb_atarget.DisplayMember = "atarget"
Next
Next
The second problem comes when I do it manually (which works) using the exact combobox names cb_aantigen and cb_atarget as seen in the comments.
The problem is that once the form is loaded and the cb's are filled with the correct values, I can't change the value in any single cb individually, when I change one value it changes them all (there is 15 comboboxes in total) I know this is down to using a dataset, but I don't know away to 'unlink them from each other or the dataset'
Not sure if I need to split this into 2 questions, but help on either problem would be appreciated.
EDIT:
After looking at only this section of code for a day. This is what I have come up with to tackle both the problems at once.
The combobox control not working was down to using a tab tc_opt instead of a groupbox gp_anti
The issue with splitting the dataset up into individual comboboxes, I've worked around by taking the value of each cell in the database and adding it separately, probably a better way to do it though
For Each dstable As DataTable In dstcopt.Tables
For Each dscolumn As DataColumn In dstable.Columns
Dim colName As String = dscolumn.ToString
Dim cb(2) As ComboBox
cb(0) = CType(Me.gp_anti.Controls("cb_" & colName), ComboBox)
cb(1) = CType(Me.gp_rec.Controls("cb_" & colName), ComboBox)
cb(2) = CType(Me.gp_nat.Controls("cb_" & colName), ComboBox)
For icb = 0 To cb.Count - 1
If Not (IsNothing(cb(icb))) Then
For irow = 0 To dstable.Rows.Count - 1
If dstable.Rows(irow)(colName).ToString <> Nothing Then
Dim icbitemdupe As Boolean = False
If cb(icb).Items.Contains(dstable.Rows(irow)(colName).ToString) Then
icbitemdupe = True
End If
If icbitemdupe = False Then
cb(icb).Items.Add(dstable.Rows(irow)(colName).ToString)
End If
End If
Next
End If
Next
Next
Next
I have a listview, lvSelectRequestItems that contains three columns. 'Box, 'Custref' and 'description'. At the moment the code I am using returns all items in all 3 columns. However, what I would like to do is just return box and description. Can someone show me how to adjust my code to achieve that. Thank you.
For Each item As ListViewItem In Me.lvSelectRequestItems.SelectedItems
item.Remove()
Me.lvSelectedItems.Items.Add(item)
Next
write this way:
try this:
1 ,3 is your colums index
For Each item As ListViewItem In Me.lvSelectRequestItems.SelectedItems
item.Remove()
Dim li As New ListViewItem
li.Text = item.SubItems(1).Text
li.SubItems.Add(item.SubItems(3).Text)
Me.lvSelectedItems.Items.Add(li)
Next
I have list of columns in DataTable to be added in list view. I have specified to the listview of columns in the order to appear and Datas as well.
EmailAddress Subject RecievedDate
cd#cd.in Hello 02/06/2011 23:00
This the format to appear.Please anyone can help on this
EDIT:
Code so far:
For i = 0 To objDataTable.Rows.Count drow = objDataTable.Rows(i)
Dim lvwItem As ListViewItem = New lvwItem(drow("SenderEmail"))
'lvwItem.SubItems.Add(drow("SenderEmail"))
lvwItem.SubItems.Add(drow("EmailSubject"))
lvwItem.SubItems.Add(drow("RecievedDate").ToString())
lvwItem.SubItems.Add(drow("AssignedTo").ToString())
LOV.Items.Add(lvwItem)
Next
Your code sample looks almost correct. One error is this line:
Dim lvwItem As ListViewItem = New lvwItem(drow("SenderEmail"))
This should be:
Dim lvwItem As ListViewItem = New ListViewItem(drow("SenderEmail").ToString())
Apart from that you need to make sure your listview is in details view and you actually have the columns you require (otherwise nothing will be shown when in details view):
With listview1
.View = View.Details
.Columns.Add("Email Address")
.Columns.Add("Subject")
.Columns.Add("Recived Date")
'etc
End With
One other small issue is This line:
For i = 0 To objDataTable.Rows.Count
Should be
For i = 0 To objDataTable.Rows.Count - 1
Hey all i am trying to find a way to add something to one of the columns in my listview. The way my code is setup is like this:
While dr.Read()
If dr.IsDBNull(12) Then
objItem = lstMaster.Items.Add("nothing")
Else
objItem = lstMaster.Items.Add(dr(12))
End If
With objItem
If dr.IsDBNull(11) Then
.SubItems.Add("nothing")
Else
.SubItems.Add(dr(11))
End If
How can i just tell it to put it in the 3rd column (i have 5 total (0-4)) instad of just going down the roll and it falls in order?
Any help would be great! :o)
David
Add as many sub-items as you have columns. Then just index the sub-item you want to change. For example:
Dim item = ListView1.Items.Add("Test")
For cnt As Integer = 1 To ListView1.Columns.Count
item.SubItems.Add("")
Next
item.SubItems(3).Text = "Blah"