List View
-
Upload
didit-adja -
Category
Documents
-
view
11 -
download
0
Transcript of List View
VB.NET ListView Tutorial. Add, Edit and DeleteOne of my most commonly used VB.NETcontrolto present a spread-sheet like information is theListViewcontrol. According to msdn, a list-viewcontrolis a window thatdisplaysa collection of items using one of four different views. List-view controls provide several ways to arrange and display items and are much more flexible than simple List Boxes.On thisarticle, I will discussthe basicsof adding, editing and deleting items in listview. A complete sampleprojectcan be downloaded at the end ofthis post.
At the end ofthe tutorial, you will be able to do the following tasks:1. Properly configure ListView to display spread-sheet information2.Add Itemson ListView3. Edit Item on ListView4. Delete Item on ListView
Here are the step-by-step to create our list view tutorialproject.1. Create a newprojectin VB.NET2. Put the following controls as shown below on your initial form
3. Set the ListViewcontroland set the following properties from the Property window.a. FullRowSelect = Trueb. GridLines = Truec. HideSelection = Falsed. MultiSelect = Falsee. View = Details
4. Declare blnAdd variable that will indicate if Add button was pressed.1. DimblnAddAsBoolean'indicatorifaddbuttonwaspressed
5. On your add button, put the following codes:1. PrivateSubbtnAdd_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesbtnAdd.Click2. 3. IfbtnAdd.Text.ToLower()="add"Then'ifcaptionisADDthenperformAddprocess4. txtFirstName.Enabled=True5. txtLastName.Enabled=True6. btnAdd.Text="Save"7. btnEdit.Text="Cancel"8. btnDelete.Enabled=False9. txtFirstName.Text=""10. txtLastName.Text=""11. blnAdd=True12. 13. Else'saveprocess14. txtFirstName.Enabled=False15. txtLastName.Enabled=False16. btnAdd.Text="Add"17. btnEdit.Text="Edit"18. btnDelete.Enabled=True19. IfblnAddThen20. AddItemToListView()21. Else22. EditItemInListView()23. EndIf24. 25. EndIf26. EndSub
Also include these codes below the btnAdd_Click, these functions are for adding and editing listview items.1. '''2. '''Addlistviewitems3. '''4. '''5. PrivateSubAddItemToListView()6. 'Usuallythefirstuniquecolumistherootitem7. DimlvAsListViewItem=ListView1.Items.Add(txtFirstName.Text)8. 'Theremainingcolumnsaresubitems9. lv.SubItems.Add(txtLastName.Text)10. EndSub11. '''12. '''EditIteminListView13. '''14. '''15. PrivateSubEditItemInListView()16. IfListView1.SelectedItems.Count>0Then'makesurethereisaselecteditemtomodify17. ListView1.SelectedItems(0).Text=txtFirstName.Text18. ListView1.SelectedItems(0).SubItems(1).Text=txtLastName.Text19. EndIf20. EndSub
6. On the edit button, place the following codes.1. PrivateSubbtnEdit_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesbtnEdit.Click2. IftxtFirstName.Text.Length>0Then3. IfbtnEdit.Text.ToLower()="edit"Then'ifcaptionisEDITthenperformEDITprocess4. txtFirstName.Enabled=True5. txtLastName.Enabled=True6. btnAdd.Text="Save"7. btnEdit.Text="Cancel"8. btnDelete.Enabled=False9. blnAdd=False10. Else'cancelprocess11. txtFirstName.Enabled=False12. txtLastName.Enabled=False13. btnAdd.Text="Add"14. btnEdit.Text="Edit"15. btnDelete.Enabled=True16. EndIf17. Else18. MessageBox.Show("Pleaseselectrecordtoedit")19. EndIf20. 21. EndSub
7. While on the delete button, copy-and-paste these codes:1. PrivateSubbtnDelete_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesbtnDelete.Click2. IfListView1.SelectedItems.Count>0AndAlsoMessageBox.Show("Doyouwanttodeletethisitem?","Confirm",MessageBoxButtons.YesNo)=Windows.Forms.DialogResult.YesThen'makesurethereisaselecteditemtodelete3. ListView1.SelectedItems(0).Remove()4. EndIf5. EndSub
8. To select an item and put the values on the respective textboxes, use the following codes:1. PrivateSubListView1_SelectedIndexChanged(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesListView1.SelectedIndexChanged2. IfListView1.SelectedItems.Count>0Then3. txtFirstName.Text=ListView1.SelectedItems(0).Text4. txtLastName.Text=ListView1.SelectedItems(0).SubItems(1).Text5. EndIf6. EndSub
Chart Control VB.NET 20107. Hi Everybody,I would like to explain one of faq within this essay , how can I can use chart control with VB.NET windows application? If any question, please feel free and contact me [email protected] or [email protected].
1-) We are creating a new Windows Application Project (chart_control1)
2-) We are designing this windows form in a similar way to bellowing picture
3-) Series Collection(Student)
4-) We are writing this code
Private Sub chart_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chart_btn.Click
Chart1.Series("Student").Points.AddXY("Jon", 10)Chart1.Series("Student").Points.AddXY("Jordan", 30)Chart1.Series("Student").Points.AddXY("Yen", 40)Chart1.Series("Student").Points.AddXY("Nick", 20)
Chart1.Series("Student").ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Bar
End Sub
5-) Lets run application and click show button
6-) Change codes and run again
Private Sub chart_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chart_btn.Click
Chart1.Series("Student").Points.AddXY("Jon", 10)Chart1.Series("Student").Points.AddXY("Jordan", 30)Chart1.Series("Student").Points.AddXY("Yen", 40)Chart1.Series("Student").Points.AddXY("Nick", 20)
Chart1.Series("Student").ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie
End Sub
7-) For 3D and run again
Private Sub chart_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chart_btn.Click
Chart1.Series("Student").Points.AddXY("Jon", 10)Chart1.Series("Student").Points.AddXY("Jordan", 30)Chart1.Series("Student").Points.AddXY("Yen", 40)Chart1.Series("Student").Points.AddXY("Nick", 20)
Chart1.Series("Student").ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie
Chart1.Series("Student")("PieLabelStyle") = "Outside"
Chart1.ChartAreas("ChartArea1").Area3DStyle.Enable3D = True
End Sub