Tom

Tom

  • NA
  • 1
  • 0

CurrentCellChanged in DatagridView

Dec 7 2005 4:21 PM
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); desktop.Show(); } 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) (X=1,Y=0) (X=-1,Y=-1) (X=1,Y=0) (X=-1,Y=-1) (X=1,Y=0) 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 ?