Thursday, April 12, 2018

How to show ListView data in TextBox in Visual Basic6.0 Tips

How to show ListView data in TextBox in Visual Basic6.0 Tips

A developer require something new to develop any application or software. For new programmer in Visual Basic, always face some types of basic problem. In the same way, we learn about show ListView data in TextBox or any other control in Visual Basic with its related features.
So, for showing items from Listview to TextBox, we have to follow the some following steps. When you process on this control then you always think some questions Like:
How to display items to TextBox in VB?
How to get items from this control to TextBox?
....etc.

SkoTechLearn will solve all related questions described above.

 Step 1: Add Data or Items to ListView
If you want to show items in TextBox, you have to remember that this control cannot empty or without items. At least one record associated with this control as shown in bellow image. Check here to Add Data or Items.
ListView Data for show in textbox
Item's View
Suppose, we define 4 columns with Column Header: EMP_Name, EMP_Age, EMP_Address, EMP_MoNo And there is 4 records related with these column.

Suppose, we have 4 TextBox with textname: 'EMPName_Txt', 'EMPAge_Txt', 'EMPAddress_Txt', 'EMPMono_Txt'. And selected item must be display in given related box. I also drag some Label to define the this box related Name to easily understand which text present the column value.

Here, we will change Listview1 Name as Lstvdata1.
 Step 2: Show Selected Items In TextBox
For display record in TextBox follow the steps as describe bellow.

1.Double click on Lstvdata1
2.Select "ItemClick" events from event selection box like bellow.

Code Window (ItemClick Event)
Private Sub Lstvdata1_ItemClick(ByVal Item As MSComctlLib.ListItem)

End Sub
ListView code event for show data in Textbox
Code Window with Lstvdata1 Event
There is another way to reach event window, just right click on control and select "View Code" option from drop down menu. But if you want to reach that particular control's code event, just double click on that control. After that type code in "Lstvdata1_ItemClick(ByVal Item As MSComctlLib.ListItem)" events.
Follow Sample Code:
Private Sub Lstvdata1_ItemClick(ByVal Item As MSComctlLib.ListItem)

 EMPName_Txt.Text = Lstvdata1.SelectedItem.Text
 EMPAge_Txt.Text = Lstvdata1.SelectedItem.SubItems(1)
 EMPAddress_Txt.Text = Lstvdata1.SelectedItem.SubItems(2)
 EMPMoNo_Txt.Text = Lstvdata1.SelectedItem.SubItems(3)

End Sub
OR
Private Sub Lstvdata1_ItemClick(ByVal Item As MSComctlLib.ListItem)

 EMPName_Txt.Text = Item.SelectedItem.Text
 EMPAge_Txt.Text = Item.SelectedItem.SubItems(1)
 EMPAddress_Txt.Text = Item.SelectedItem.SubItems(2)
 EMPMoNo_Txt.Text = Item.SelectedItem.SubItems(3)

 End Sub

 Step 3: Run Application to View output
After apply above code, run project. After that click or select any one of row data , as well as you select row data, it will show in its related Box.

Selection of record can be proceed by pressing arrow up and arrow down key.
ListView Item Selection for show data in Textbox
Lstvdata1 Item Selection
This will present if we click or select any row items from this control. It shows record in its related Box.

This is the simple look of presenting to easily understand. This has some feature to design or change look according to your desire. This control is only way to fast item's presentation. It can take less time to show items compare than any other Table's control.

This is the step by step instruction to show ListView data in TextBox in Visual Basic6.0 easy Tips with SKOTechLearn.

0 comments: