473,785 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's wrong with this Find on a DataView?

Dim dv As DataView = New DataView(Facili tiesDS1.Facilit ies, "", "ID
ASC", DataViewRowStat e.CurrentRows)
Dim iPos As Integer = dv.Find(dr.Item ("ID"))
Me.BindingConte xt(FacilitiesDS 1, "Facilities").P osition = iPos

That is the code.. dr is DataRow. If dr.Item("ID") = 3, the find will
return position 0, which it should have been 1, and if the ID = 2, it
will return 1, which should have been 0.. The DA has a connection string
that sorts it by name, not ID... Is that where I am running into trouble
here??? ID is the primary key...

Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #1
4 2619
Your code looks correct.

You may already be familiar with these debugging techniques, but just in
case, I will tell you what I would do:

When you are stepping through the code, you can highlight any section of
code that will return a basic type, and you will see the value displayed when
you lay your mouse cursor over the highlighted text.

Highlight: dr.Item("ID"), and check to make sure you have the expected value.

In the Command Window-Immediate, during the step through:

Type: ? FacilitiesDS1.F acilities.rows( 0).item("ID")
and Enter, to check the datatable rows as they exist in the datatable. Then
check the dataview with ? dv.item(0).item ("ID"), etc

Use the up arrow to repeat the line, and put in other rows to make sure the
rows are as you expect.

Since you are sorting the datatable by name, the ID fields will not be in
order in the datatable, but when you pass "ID" as the sort key parameter when
constructing the dataview, the dataview will re-sort on that field.
Dataview.Find only works on the Sort field, and Sort must be set in order to
use Find. It finds the first matching item in that field, and returns the
row.

Hope that helps.

www.charlesfarriersoftware.com

"Aaron Smith" wrote:
Dim dv As DataView = New DataView(Facili tiesDS1.Facilit ies, "", "ID
ASC", DataViewRowStat e.CurrentRows)
Dim iPos As Integer = dv.Find(dr.Item ("ID"))
Me.BindingConte xt(FacilitiesDS 1, "Facilities").P osition = iPos

That is the code.. dr is DataRow. If dr.Item("ID") = 3, the find will
return position 0, which it should have been 1, and if the ID = 2, it
will return 1, which should have been 0.. The DA has a connection string
that sorts it by name, not ID... Is that where I am running into trouble
here??? ID is the primary key...

Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.

Nov 21 '05 #2
I stepped through the code yesterday and what I discovered is that I
guess it's actually working correctly, just not how I want it to. When
you apply the sort, it doesn't resort the table.. So the find is
actually working correctly and finding the right position based on the
sort, it's just in the same order.

Here is what I was trying to do, and maybe someone can help me here.
I have a lookup on the table so they can use a grid to sort and quickly
find a record in the table. When that lookup closes, I want to find the
record they selected and go to it. Here is the problem. The table is
sorted by name, but name is not a unique value, the ID field is. When
you tell it to sort by ID, it does, but the position it finds when you
find that record, is not the same as the position in the binding
context. I know there has to be an easy way to do this, any suggestions?

Aaron

Charlie wrote:
Your code looks correct.

You may already be familiar with these debugging techniques, but just in
case, I will tell you what I would do:

When you are stepping through the code, you can highlight any section of
code that will return a basic type, and you will see the value displayed when
you lay your mouse cursor over the highlighted text.

Highlight: dr.Item("ID"), and check to make sure you have the expected value.

In the Command Window-Immediate, during the step through:

Type: ? FacilitiesDS1.F acilities.rows( 0).item("ID")
and Enter, to check the datatable rows as they exist in the datatable. Then
check the dataview with ? dv.item(0).item ("ID"), etc

Use the up arrow to repeat the line, and put in other rows to make sure the
rows are as you expect.

Since you are sorting the datatable by name, the ID fields will not be in
order in the datatable, but when you pass "ID" as the sort key parameter when
constructing the dataview, the dataview will re-sort on that field.
Dataview.Find only works on the Sort field, and Sort must be set in order to
use Find. It finds the first matching item in that field, and returns the
row.

Hope that helps.

www.charlesfarriersoftware.com

--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #3
I use a derived grid for allowing the user to locate a record, much as you
are describing. There may be a better way to do this, but I found a way to
assure that the Key (or ID) value was properly identified.

I provide a hidden (or unhidden) column in the datagrid for the Key

I allow the user sort the grid by column, so to get the key, I extract it
out of the grid in the mousedown event, using a HitTest, instead of trying to
identify it in the row of the underlying data...

Private Sub DataGrid1_Mouse Down(ByVal sender _
As System.Object, ByVal e As _
System.Windows. Forms.MouseEven tArgs) _
Handles DataGrid1.Mouse Down
Dim Key As String
Dim HTI As DataGrid.HitTes tInfo = _
DataGrid1.HitTe st(e.X, e.Y)
Select Case DataGrid1.HitTe st(e.X, e.Y).Type
Case DataGrid.HitTes tType.RowHeader , _
DataGrid.HitTes tType.Cell
Key = DataGrid1.Item( HTI.Row, 0)
End Select
End Sub

This is a simplified version of what I have in the derived control, and I
did not test this code, but it should work, or at least be close.

The Column containing the Key may be hidden by using TableStyles for the
DataGrid, and setting the Key column width to 0. In the code above, the Key
is in Column 0 of the grid.

Hope that helps.

www.charlesfarriersoftware.com
"Aaron Smith" wrote:
I stepped through the code yesterday and what I discovered is that I
guess it's actually working correctly, just not how I want it to. When
you apply the sort, it doesn't resort the table.. So the find is
actually working correctly and finding the right position based on the
sort, it's just in the same order.

Here is what I was trying to do, and maybe someone can help me here.
I have a lookup on the table so they can use a grid to sort and quickly
find a record in the table. When that lookup closes, I want to find the
record they selected and go to it. Here is the problem. The table is
sorted by name, but name is not a unique value, the ID field is. When
you tell it to sort by ID, it does, but the position it finds when you
find that record, is not the same as the position in the binding
context. I know there has to be an easy way to do this, any suggestions?

Aaron

Charlie wrote:
Your code looks correct.

You may already be familiar with these debugging techniques, but just in
case, I will tell you what I would do:

When you are stepping through the code, you can highlight any section of
code that will return a basic type, and you will see the value displayed when
you lay your mouse cursor over the highlighted text.

Highlight: dr.Item("ID"), and check to make sure you have the expected value.

In the Command Window-Immediate, during the step through:

Type: ? FacilitiesDS1.F acilities.rows( 0).item("ID")
and Enter, to check the datatable rows as they exist in the datatable. Then
check the dataview with ? dv.item(0).item ("ID"), etc

Use the up arrow to repeat the line, and put in other rows to make sure the
rows are as you expect.

Since you are sorting the datatable by name, the ID fields will not be in
order in the datatable, but when you pass "ID" as the sort key parameter when
constructing the dataview, the dataview will re-sort on that field.
Dataview.Find only works on the Sort field, and Sort must be set in order to
use Find. It finds the first matching item in that field, and returns the
row.

Hope that helps.

www.charlesfarriersoftware.com

--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.

Nov 21 '05 #4
Also, you probably already know this, but jic..
To get the DataRow from the DataTable, using the Key:
DR = DT.Rows.Find(Ke y)
To use rows.find, the Datatable must have its PrimaryKey property defined.

"Aaron Smith" wrote:
I stepped through the code yesterday and what I discovered is that I
guess it's actually working correctly, just not how I want it to. When
you apply the sort, it doesn't resort the table.. So the find is
actually working correctly and finding the right position based on the
sort, it's just in the same order.

Here is what I was trying to do, and maybe someone can help me here.
I have a lookup on the table so they can use a grid to sort and quickly
find a record in the table. When that lookup closes, I want to find the
record they selected and go to it. Here is the problem. The table is
sorted by name, but name is not a unique value, the ID field is. When
you tell it to sort by ID, it does, but the position it finds when you
find that record, is not the same as the position in the binding
context. I know there has to be an easy way to do this, any suggestions?

Aaron

Charlie wrote:
Your code looks correct.

You may already be familiar with these debugging techniques, but just in
case, I will tell you what I would do:

When you are stepping through the code, you can highlight any section of
code that will return a basic type, and you will see the value displayed when
you lay your mouse cursor over the highlighted text.

Highlight: dr.Item("ID"), and check to make sure you have the expected value.

In the Command Window-Immediate, during the step through:

Type: ? FacilitiesDS1.F acilities.rows( 0).item("ID")
and Enter, to check the datatable rows as they exist in the datatable. Then
check the dataview with ? dv.item(0).item ("ID"), etc

Use the up arrow to repeat the line, and put in other rows to make sure the
rows are as you expect.

Since you are sorting the datatable by name, the ID fields will not be in
order in the datatable, but when you pass "ID" as the sort key parameter when
constructing the dataview, the dataview will re-sort on that field.
Dataview.Find only works on the Sort field, and Sort must be set in order to
use Find. It finds the first matching item in that field, and returns the
row.

Hope that helps.

www.charlesfarriersoftware.com

--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6578
by: MajorTom | last post by:
Hello I need help. I have a datagrid that have a dataview as datasource. in the keyup event of one textbox I use dataview.rowfilter = some.text; when the condition of my rowfilter return some rows, everything works fine. At the point that the rows returned by the rowfilter is cero (0), the datagrid don't get the rows even if I use a new rowfilter with results, the
5
9178
by: BBFrost | last post by:
Win2000 ..Net 1.1 SP1 c# using Visual Studio Ok, I'm currently in a "knock down - drag out" tussle with the .Net 1.1 datagrid. I've come to realize that a 'block' of rows highlighted within a datagrid do >> not << constitute a set of 'selected' records. Apparently one and only one row may be 'selected' in a datagrid. By selected row I mean the row
1
33395
by: ad | last post by:
What is the difference between DataRow and DataRowView?
3
2166
by: oscar | last post by:
i've created a search function, using vc#, and i'm using the dataview.find() method to get the index of the found record. the problem is that there are many similar names. it always returns the same index, but it can be any one of the items. as an example, if i type in the work "bolt" it will return the index 1201, the first "bolt" is at 1120 and the last one is at 1294. it is for a point of sale program and i have no control over the...
3
1117
by: Cesar Ronchese | last post by:
Hey guys. I'm using a DataView to store a lot (amoung 2000 lines) of configuration and objects and this DataView is indexed by two columns. That 2000 lines are created in a loop, with the DataView already indexed to improve search, because I need to check if the record already exists before create a new. The problem I noticed is this is too low to store new data, perhaps because the index engine is not optimized for that kind of use.
7
1212
by: John 3:16 | last post by:
Hello... I have a question related to performance. Being new to asp.net & vp programming, I put together a webform that displays columns of data in a datagrid. Users can sort by the header label. QUESTION: When they click to sort, I run a new stored procedure to return the resorted data... Should I only get the data once and query the
4
14649
by: =?Utf-8?B?UmljaA==?= | last post by:
Is it possible to use a wildcard like feature with Dataview.Find? Actually, I tried that but did not get any rows. Is there some wildcard like feature of the dataview or some other object that I could search/find rows in an ADO.Net dataTable? Or, am I stuck having to write a loop and search the loop for a substring of an expression?
3
4077
by: shapper | last post by:
Hello, I need to loop though each row in a GridView and if the checkbox is a Template Field is checked I want to display the value of an invisible column named "LevelName". I tried everything I could think off but I always get an error or no value. Could someone please let me know what might be wrong?
0
951
by: Michael_R_Banks | last post by:
I have a table ("checkout") that I'm tracking equipment checkout transaction. It has columns: checkoutid (key), checkedbyid, checkedtoid, dateout, datein and inventoryid. When the user scans an equipment barcode (Entry), I'm trying to check if that equipment was previously checked out, but not properly checked back in by looking up the inventoryid and then searching for a blank datein field. I've declared the dataview with: Dim dvChk...
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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,...
0
10319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10087
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,...
0
9947
tracyyun
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...
1
7496
isladogs
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...
0
5380
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.