473,474 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

BindingManager detecting new row

Hi,

I have two tables and a dataRelation (win forms project). The dataRelation
is bound to a dataGrid. I'm trying to detect when a user navigates to a new
row in the datagrid so I can obtain a new record ID number from the db.

Screenshot:
http://www.insightgis.com.au/web/stu...row_detect.gif
I do all this by assinging an event handler on the BindingManagerBase. The
sample code below works fine if the dataGrid is bound to a base table, but
throws an exception when bound to a relation. This is the line that makes
the baby cry - it's not happy casting the grid's dataSrouce as a DataTable:

bool lastRow = bm.Count > ((DataTable)myDataGrid.DataSource).Rows.Count

....... Declare the bindingManagerBase variable:

private BindingManagerBase bm
....... Create the event on the bindingManager:

bm = this.BindingContext[myDataGrid.DataSource,
"myParentTable.myChildRelation"];
bm.PositionChanged += new EventHandler(bm_PositionChanged);

....... Event handler:

private void bm_PositionChanged(object sender, EventArgs e)
{
try
{
// Check if we are on a new row.

bool lastRow = bm.Count > ((DataTable)myDataGrid.DataSource).Rows.Count;
// Above line throws an exception "Specified cast is not valid".
// This only happens when the datagrid is bound to a relation, works
// fine on base tables.

if (lastRow)
{
string sNewID = ..... Fire off stored procedure to get next ID .....
DataRowView drv = (DataRowView) bm.Current;
drv["LIST_ID"] = sNewID;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
I repeat once more, all of the above works fine except when the dataGrid is
bound to a relation.

Anyone have any ideas?

Cheers,
PeterZ
Nov 16 '05 #1
1 1988
Peter,

Because in principle the dataset is disconnected is the method you are using
not always the one, did you already looked at the autoincrement.

http://msdn.microsoft.com/library/de...entcolumns.asp

I give you this link just as a starting place, there is a lot of more
information about this I thought by instance on Bill Vaughn website.

I hope this helps?

Cor
Nov 16 '05 #2

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

Similar topics

5
by: Jole | last post by:
Hi I'm writing a program that needs to read from a file. In order for the program to be robust, it should somehow check that the file isn't corrupt, or stuffed in any way. For example, that...
15
by: Jay | last post by:
I'm sure this is a really dumb question, but how do you detect a variable type in Python? For example, I want to know if the variable "a" is a list of strings or a single string. How do I do...
3
by: raptor | last post by:
hi, how to detect opera..it seems that even opera8 doesnt support xmlhttp fully (.i.e. sendRequestHeader). I ask this 'cause opera seems to mimic IE, at least in the preferences ?! I havent...
0
by: PeterZ | last post by:
Hi, I have two tables and a dataRelation (win forms project). The dataRelation is bound to a dataGrid. I'm trying to detect when a user navigates to a new row in the datagrid so I can obtain a...
9
by: D. Shane Fowlkes | last post by:
I'm using SQL Server 2000 and on my page, I'm simply creating a SQLDataReader and filling in Labels with the retrieved (single) record. However, how can I prevent from getting errors when a field...
3
by: regtrashcan | last post by:
I have a webpage that detects whether Shockwave Player is installed and the version number. The javascript/vbscript that I use has worked fine until the latest release of the Shockwave Player. I am...
79
by: VK | last post by:
I wandering about the common proctice of some UA's producers to spoof the UA string to pretend to be another browser (most often IE). Shouldn't it be considered as a trademark violation of the...
5
by: Z.K. | last post by:
In C#, using the StreamReader, how do I detect when you get to the end of line. I am reading a text file using the Read() function and I need to detect the \n\r, but everything I try does not...
1
by: wwwords | last post by:
Is there a general method for detecting that a user has changed the record currently visible on a form, whether this is by hitting PgUp or PgDn or clicking on a navigation button, even if no change...
0
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...
0
jinu1996
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...
1
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.