Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Code to realize VB.NET ListView loading data

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

How to use code to achieve VB.NET ListView loading data, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

VB.NET is still quite commonly used, so I studied VB.NET ListView and took it out here to share with you. I hope it will be useful to you. Usually we develop database-related programs in VB.NET will use DataGrid to display data, its use is relatively simple, but also has the function of sorting, basically can meet the general requirements. But sometimes it can not meet the functional requirements of the project, then we think of using VB.NET ListView, although its function is exactly what we want, must compete it is not a database control, can not be like DataGrid through simple settings to display data, at the same time there is no sorting function, we have to use our own program code to achieve.

A few days ago, when developing a project, I wrote a section of code that uses VB.NET ListView to display data and achieve sorting, and simply talk about its implementation principle: display data is read through the cycle to read the data record, using VB.NET ListView's Add method to add data to the ListView; sorting function is through the click event of the ListView column to get the fields to be sorted, and then use the ORDER BY keyword to combine SQL to reload data to achieve sorting.

The following is the setting information of the database and controls used by the program:

Database name: Northwind (included in SQL SERVER 2000. If you do not have this database, please create it first)

Table name: Products (if you do not have this table, use the attached SQL statement to create it)

Window body name: frmListViewDb

Imports System.Data.SqlClient Public Class frmListViewDb Inherits System.Windows.Forms.Form 'defines the database connection object Dim sdConn As New SqlConnection Dim conString As String = "data source=127.0.0.1;initial catalog=Northwind;uid=sa" Password=123456 "'define the variable of the db2ListView execution status of the record Dim Dbr As Integer' define the variable of the default sorting method of the record Dim mySort As String =" ASC "'define the variable of the default sort field of the record Dim myField As String =" ProductID "' define the last sorted field of the record column ID in LISTVIEW variable Dim pOrderID As Integer = 0 'define the related variable Dim i As Integer Dim sCount As Integer of the check operation # Region "code generated by the Windows forms designer" Public Sub New () MyBase.New () 'this call is required by the Windows forms designer. InitializeComponent () 'add any initialization End Sub' form after the InitializeComponent () call to rewrite the dispose to clean up the component list. Protected Overloads Overrides Sub Dispose (ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose () End If End If MyBase.Dispose (disposing) End Sub, is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report