Dim dv As DataView = New DataView(FacilitiesDS1.Facilities, "", "ID
ASC", DataViewRowState.CurrentRows)
Dim iPos As Integer = dv.Find(dr.Item("ID"))
Me.BindingContext(FacilitiesDS1, "Facilities").Position = 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. 4 2596
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.Facilities.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(FacilitiesDS1.Facilities, "", "ID ASC", DataViewRowState.CurrentRows) Dim iPos As Integer = dv.Find(dr.Item("ID")) Me.BindingContext(FacilitiesDS1, "Facilities").Position = 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.
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.Facilities.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.
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_MouseDown(ByVal sender _
As System.Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) _
Handles DataGrid1.MouseDown
Dim Key As String
Dim HTI As DataGrid.HitTestInfo = _
DataGrid1.HitTest(e.X, e.Y)
Select Case DataGrid1.HitTest(e.X, e.Y).Type
Case DataGrid.HitTestType.RowHeader, _
DataGrid.HitTestType.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.Facilities.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.
Also, you probably already know this, but jic..
To get the DataRow from the DataTable, using the Key:
DR = DT.Rows.Find(Key)
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.Facilities.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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
by: ad |
last post by:
What is the difference between DataRow and DataRowView?
|
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...
|
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...
|
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....
|
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...
|
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...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |