# vb.net Datagridview



## StevenSmith (Jan 7, 2009)

Hi 
I am having the following problem with a data grid (This is my child grid). My data grid is bound to a binding source which is bounded to a dataset filled with data. 
I want the user to be able to add new rows and as they add rows certain fields needs to be populated (There fields is not visible in my grid) with data from my parent dataset.
I add the data in the following handler

```
AddHandler dataset.table.TableNewRow, AddressOf AddNewPreRow
```


```
Private Sub AddNewPrePopulatedWarehouseLocationRow(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs)
            e.Row.Item("ColumnName") = CStr(SelectedParentRow.ColumnName)             
        End Sub
```
If the user moves to a new row the values is populated (if I make the invisible columns visible I can see that they do get populated) and if the user goes back the row
disappears like i want to. I also do a validation on the CellEndEdit and in here I make use of the rowindex. 

But the problem comes when the user goes to the new line enter a value in the first cell (By this time the dgv seems to be taking this as a new row and it is not "Dirty anymore"
And it shows a new line with * beneath this line) which is all ok.....

This far we have 2 lines - 
1. The line that i just created and added info into the first column (This line has a pencil next to it)
2. An empty line beneath it (This line has a * next to it)

If i use the mouse and click on another row
1. The newly add line with the pencil next to it cleans itself (I suppose this is because i did not enter all the required fields yet and the data binding discards the data)
But the empty line remains there
2. Now the validation fires for this line and a get a Index <XX> does not have a value
3. There is now 2 empty lines then new one now has a Play button sign and the line beneath it has a *

In my validation i check for the following to execute validation
If (dgv.Rows(RowIndex) IsNot Nothing) AndAlso Not dgv.Rows(RowIndex).IsNewRow AndAlso dgv.IsCurrentRowDirty Then --> result in true

Please if someone knows how to fix this i will appreciate it.

Thanks,
Steven


----------

