row index

  • Thread starter Thread starter Bernie Yaeger
  • Start date Start date
B

Bernie Yaeger

I picked up the thread of a different question in a different newsgroup, but
it belongs here:

having found the row where the 'addr' column begins with 'G', I want the
first one - not Gerber or Gorsky, but rather Gable. So I figured out how to
do this:
ods2.Tables(0).DefaultView.Sort = "addr"

For Each irow In ods2.Tables(0).Select("addr like '" & vartopassin & "%'")

MessageBox.Show(irow("addr"))

Exit For

Next

You can't do this with a computed column, at least I wasn't successful in
doing so, because then any 'G' is first found by, say, a dataview. But the
above works just fine.

Now 'Gable Street' is the result. But here's my question: having the
datarow I want, what is its index? You sometimes must have the index.
Please don't respond to tell me 'why do you need the index?' 'why not do
this or that?' I need the index. I can get an index in a dataview because
it returns an integer. But a datarow? How does one find the index of a
given datarow?

Any help would be appreciated.

Bernie Yaeger
 
You ask a very good question...... as I had also asked several weeks
ago... about the relationship between what one sees in a DataView and the
underlaying DataTable... which we all know must be related..... so the
information must be around somewhere.. just not visible to us...... for
consumption......

My issue was..... you could click on what appeared to be row 3 and get row
43.... since you clicked on the column header and sorted the
information......... my solution (yea, I got mine working... which goes
way beyond your issue)... was to ghost the system.... and keep them in
sync behind the scenes......

I also do something like what your asking.... and I flip through all the
rows..... and locate the first row that matches the criteria... and
return back the row number..... which may or may not be in the same
position on the screen.....

HTH...... ALOHA
 
Does your dataset have a primary key? If so you could just get that
value and use it as the index.

string s = MyDataRow["myKey"].ToString();



Rob
 
Back
Top