In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is to share with you about what VB.NET DataRowView means. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Data-bound list boxes and combo boxes in Windows forms save time. The typical code is as follows (assuming that a SqlDataAdapter or other part has been established to obtain data):
Dim ds As New DataSet () SqlDataAdapter1.Fill (ds, "Customers") ListBox1.DataSource = ds.Tables ("Customers") ListBox1.DisplayMember = "CompanyName" ListBox1.ValueMember = "CustomerID"
In this case, the code uses the customer records of the Northwind database to work. The DisplayMember property is set to the record field you want the user to see in the list box, which is the CompanyName of the customers table. Usually the ValueMember property is set to a key field in the data table, which is CustomerID. CustomerID for customer. Once the user has selected a row in the list box, it is easy to get the key field using the SelectedValue property of the list box:
MsgBox (ListBox1.SelectedValue)
However, you may need a reference to the entire data row object associated with the selected item. For example, if the selected row needs to be deleted, the key is not known. You need a reference to the data row to use the Delete method.
A typical VB developer usually thinks, "I've got the key for this line, and I'm going to write some logic to find the line that uses it." This can be done, but there is a better way to implement it. You can use one line of code to get the rows of data associated with the options in the list box:
Dim dr As DataRow = CType (ListBox1.SelectedItem, DataRowView) Row
Usually this logic does not appear intuitively, even for experienced developers. To explain how this is done, I split the above line into several lines, and the following code has the same function as the above code:
Dim drv As DataRowView drv = CType (ListBox1.SelectedItem, DataRowView) Dim dr As DataRow dr = drv.Row
The VB.NET DataRowView class is a wrapper for rows of data and is used by multiple Windows forms controls. It makes it easier to display data related to rows of data in the control. When the list box is data bound to the data table (assuming that some rows in the list box are currently selected), the SelectedItem property of the list box holds a VB.NET DataRowView object.
This means that we can convert the SelectedItem property of the list box to the VB.NET DataRowView object, which is achieved in the second line of the code above. VB.NET DataRowView then exposes a Row attribute that points to the wrapped data row. The above code declares a row of data and sets the Row property.
The technique of converting the type of an object to access its interface is not often used in VB 6.0, but it is common in VB .NET. With the above example, most experienced developers quickly catch up with this technology.
References to data rows (dr) can be used to maintain rows in any way. It is possible to access any specific field in the data row. The data in a row can be changed to enable the Delete method of the data row to identify the row as deleted, or to delete the row from the rowset of the data table. The following code flag deletes a line:
Dr.Delete ()
Using the primary key (returned by ListBox.SelectedValue) to find the underlying rows of data requires a lot of code, takes a long time, and is slower to execute. It is normal for programmers who are just starting to use VB .NET to spend hours coding. Understanding the above techniques saves a lot of time, making it easier to maintain the code.
Thank you for reading! This is the end of this article on "what does VB.NET DataRowView mean?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.