Hello,
In my application I have a form with a ListView control. I have three columns and I add text to each of those columns from three text boxes using a single Click Event.
This works fine as long as I want to append the new items and subitems to the last line of my listView control. However, what I need sometimes is to edit the items and subitems at a specific row in the list.
For example, I would like to select a certain row, add the items and subitems from the text boxes and have it add those items to that line, not the last line.
My guess is that it could be done by identifying the index of a particular row and sending the items and subitems to that row based on the index. I expect that if there is already some item or subitem at that location, adding a new one will overwrite the existing one.
I know how to select a row and determine the index but I cannot figure out how to add the items to a row of that particular index.
Can anyone help me?
This is my code: -
Public Class Form1
-
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddItems.Click
-
-
Dim strItem As String
-
strItem = TextBox.Text
-
-
Dim strItem1 As String
-
strItem1 = TextBox1.Text
-
-
Dim strItem2 As String
-
strItem2 = TextBox2.Text
-
-
-
Dim item1 As New ListViewItem(strItem)
-
ListView1.Items.AddRange(New ListViewItem() {item1})
-
item1.SubItems.Add(strItem1)
-
item1.SubItems.Add(strItem2)
-
-
-
TextBox.Clear()
-
TextBox1.Clear()
-
TextBox2.Clear()
-
-
End Sub
-
-
-
-
-
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
ListView1.GridLines = True
-
ListView1.View = View.Details
-
-
-
ListView1.Columns.Add("Item Column", 150)
-
ListView1.Columns.Add("Column 2", 100)
-
ListView1.Columns.Add("Column 3", 100)
-
ListView1.Font = New Font("times", 14)
-
ListView1.FullRowSelect = True
-
-
End Sub
-
Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
-
'Inserts selected ListView Item to the designated text box when the listview item is selected
-
If ListView1.SelectedItems.Count > 0 Then
-
-
Dim selectedItem As String
-
selectedItem = ListView1.SelectedItems(0).Text
-
TextBox.Text = selectedItem
-
End If
-
-
Dim subitem1 As String
-
subitem1 = ListView1.SelectedItems(0).SubItems(1).Text()
-
TextBox1.Text = subitem1
-
-
Dim subitem2 As String
-
subitem2 = ListView1.SelectedItems(0).SubItems(2).Text()
-
TextBox2.Text = subitem2
-
-
End Sub
-
-
-
-
-
-
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
-
Dim index As Integer = ListView1.SelectedIndices(0)
-
txtIndex.text = index
-
-
End Sub
-
End Class
-
4 11992 PsychoCoder 465
Recognized Expert Moderator Contributor
This is VB.NET so I'll go a head and move this to the VB.NET forum for you so it can be seen by the proper experts :)
-
Dim tmpListItem As ListItem ' Declaration should be out of add list function
-
Set tmpListItem = UIlstItem.ListItems.Add(intIndex,strKey ,strDisplayText)
-
tmpListItem.SubItems(fieldIndex) = strDisplayString2
-
Above code format is an vb6 code and you can try this for VB.Net
@CyberSoftHari
Hello. Thank you for replying. I do not fully follow your code. Please explain the meaning of intIndex, strKey, and strDisplayText.
Also, could you explain "fieldIndex and strDisplayStrin g2? Thank you.
UiListitems-> user interface listitems
strDisplayText-> text to display in list items.
intInex->row index(number)
intFieldIndex->column index(number)
strKEY->key value for row
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Angelina |
last post by:
Hi,
I wanted to add a few items to my listview control. The
values of these will be obtained from other controls on
my interface. When the user clicks the select button,
they will need to be added to my listview. This is what i
need help doing.
I have added the columns to the listview but i now want
to add the values that correspond to these columns so
that they all appear in a single row.
|
by: Eva |
last post by:
Hi,
I wanted to know how i can enter values into a specific
column of a listview. I have tried the following code but
this seems to enter all my values into the first column!!!
Can anyone please help me out on this??
hers my code so far.....
|
by: Samuel R. Neff |
last post by:
I'm having a index problem with ListView SubItems. If I add multiple
columns to the listview and then add items with associated subitems,
the ListView displays fine. Then if I delete a column via
ListView.Columns.RemoveAt() then the ListView still displays fine.
However, if I grab a subitem value via
listView.Items.SubItems.Text
Then I get the Text of the wrong column.
|
by: Visual Systems AB \(Martin Arvidsson\) |
last post by:
Hi!
I'v been struggeling with removing selected items from a listview.
Anyone that can give me a piece of code that does this?
I am a newbee to this C# and cant figure it out....
Regards
Martin Arvidsson
|
by: Bry |
last post by:
I know you can select a single item in a list view using the following
code
listView.Items.Selected = true;
Is it possible to do this for all items in the listView control without
using a loop?
Thanks.
| |
by: V&G |
last post by:
Is there some way to specify different HorizontalAlignment values for
caption and subitems in listview?
|
by: CJ Taylor |
last post by:
I have the following code.
Dim lItem As ListViewItem
For Each lItem In Me.lv_Search.Items
lItem.Selected = True
Next
|
by: Holmes |
last post by:
Hello
Ran into a bit of a problem here and have now exhausted my resources to getting this working
What I am trying to do is load and show a simple vb form with a listbox in it
Dim frm_nc_code As New frm_nc_sen
frm_nc_code.Show(
Well what I want to have happen is it loads the form then shows all of the controls on the form (especially the listview control which should be blank at this time)
|
by: Julian Milano |
last post by:
I'm using the following code to act on only the selected items in a
listview. The items are selected via checkboxes:
Dim indexes As ListView.SelectedIndexCollection = .SelectedIndices
For Each i In indexes
ActiveXFileName = .Items(i).ToString
Call RegisterActiveXFile(ActiveXFileName)
Next
For some reason it does not work. Can someone explain why?
|
by: Mark Rae |
last post by:
Hi,
I have a bog-standard ListView control in a v1.1 C# WinForms project, with
three colums, Details View.
There is "Select All" button under the ListView control with the following
code:
foreach(ListViewItem lvi in lvBackupFiles.Items)
{
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |