get the position of a specific item using binding context

  • Thread starter Thread starter Haisheng Lin
  • Start date Start date
H

Haisheng Lin

Could you tell me more details about how to get
the position of a specific item using binding context?
-----Original Message-----
The binding context is your only option as it will provide you with the
requested functionality. As you state yourself, it's down to the "missing"
cursors, but you can obviously implement this yourself if you really need
it. What's the problem with the binding context?

--
Carsten Thomsen
Enterprise Development with Visual Studio .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Haisheng Lin said:
In vb6, I use adodc and bind the fields to textbox.text.
If I need to find the specific item, I just use
adodc.recordset.find, then the cursor will move to
the first occurence and textbox.text will show the
the item you need. But in ado.net, there is no cursor in
dataset. You have to use the position in bindcontext.
If you just need to go through items one by one, that is
ok, you just add one or subtract one from the position.
But if you need to find an item in the middle,
how can you know the position you need to move to?
Do I need to implement those search algorithems myself?


-----Original Message-----
There might be a functionality to do this, but I have seen people work
around very easily by putting another column called "rowindex" which
keeps the index stored there. [inefficient, but works]

Rahul Singh

anant systems, inc. | making information work for you

anantsystems.net | ioserver.net [Developer and Business .NET Hosting]



I have a table with two columns:
prod_id (primary key), prod_name.

I filled my dataset with this table and bind
two textboxs to the two columns.
I am trying to search a specific product
using its prod_name and I want to know
the position of this row in datatable.rows.

How can I do it?

Thank you!






.


.
 
At the July C#.NET user group in St. Louis I saw a great presentation on
databinding with datagrids. It demonstrates how to use the BindingContext
and the CurrencyManager which you can download from...

http://www.zrgwortz.com/datagrids.zip

You want to see "frmCurrencyManager1.cs" method "updateInfo()". Here is the
snippet that answers your question.

=== CODE ==========================================
//show info based on CurrencyManager:
CurrencyManager cm;
cm = (CurrencyManager)dgCustomers.BindingContext
[dgCustomers.DataSource, dgCustomers.DataMember];
lblCurrentRowIndex2.Text = "CurrentRowIndex = " + index.ToString();
//get the # of rows currently displayed in the grid:
totrows = cm.Count;
lblCurrencyManagerCount.Text = "CurrencyManager Count = " +
totrows.ToString();
//get the DataRow referenced by the current row in the grid:
DataRow dr = ((DataRowView)cm.Current).Row;
lblCustomerID2.Text = "CustomerID = " + dr["CustomerID"].ToString();
=== End CODE =======================================


Haisheng Lin said:
Could you tell me more details about how to get
the position of a specific item using binding context?
-----Original Message-----
The binding context is your only option as it will provide you with the
requested functionality. As you state yourself, it's down to the "missing"
cursors, but you can obviously implement this yourself if you really need
it. What's the problem with the binding context?

--
Carsten Thomsen
Enterprise Development with Visual Studio .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Haisheng Lin said:
In vb6, I use adodc and bind the fields to textbox.text.
If I need to find the specific item, I just use
adodc.recordset.find, then the cursor will move to
the first occurence and textbox.text will show the
the item you need. But in ado.net, there is no cursor in
dataset. You have to use the position in bindcontext.
If you just need to go through items one by one, that is
ok, you just add one or subtract one from the position.
But if you need to find an item in the middle,
how can you know the position you need to move to?
Do I need to implement those search algorithems myself?



-----Original Message-----
There might be a functionality to do this, but I have
seen people work
around very easily by putting another column
called "rowindex" which
keeps the index stored there. [inefficient, but works]

Rahul Singh

anant systems, inc. | making information work for you

anantsystems.net | ioserver.net [Developer and
Business .NET Hosting]



I have a table with two columns:
prod_id (primary key), prod_name.

I filled my dataset with this table and bind
two textboxs to the two columns.
I am trying to search a specific product
using its prod_name and I want to know
the position of this row in datatable.rows.

How can I do it?

Thank you!






.


.
 
Back
Top