471,627 Members | 2,330 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

CurrentCellChanged in DatagridView

Hello, I'm a kind of newbie in C# and I've a question regarding the
DataGridView control in VS2005. The problem I have is the following:

I have a form with some labels on it, when a user clicks on it another form
is called. This last form contains a split container with in the left part a
datagridview. In the right part i've added a label which shows a value from a
column in the datagrid. So when i change the row, the label must be updated
with the value of the currently selected row. This works fine with the
currentCellChanged event. However when i press the label on the first form, i
see (via debug) that the constructor of the second form is called, in this
part i also populate the datagridview.

The steps above are done in the following code excerpt:
private void LabelHandler(object sender, System.EventArgs e) {
frmDesktop desktop = new frmDesktop(((Label)sender).Text);

However i have an error when the statement desktop.Show() is launched. For
some reason the currentcellchanged is called five times. When i read out the
currentCellAddress i got the following: (ps. there are currently four rows in
the grid, add row is disabled)

Why is this currentCellChanged event called that often just when launching
the form?

As you can derive from the values above it's necessary to test on the
currentCellAddress values. Since the second and the fourth call result in a
nullreference exception when setting the text of label in the right to the
value of the grid

Anybody an idea what's the problem ? Or is this normal ?

Kind regards,
Dec 8 '05 #1
0 2818

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Lester Moreno | last post: by
4 posts views Thread by Suzanne | last post: by
1 post views Thread by J | last post: by
1 post views Thread by jason via DotNetMonster.com | last post: by
7 posts views Thread by Mitchell S. Honnert | last post: by
7 posts views Thread by =?Utf-8?B?TG9zdEluTUQ=?= | last post: by
reply views Thread by jeastman - Hotmail | last post: by
3 posts views Thread by Andrus | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

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.