Simple Datagrid question

  • Thread starter Thread starter Miro
  • Start date Start date
M

Miro

Simple perhaps to you - but not to me. :-)

Here is a quick question I just cant seem to find a solution for. (im using
vb.net but i dont think that matters in this case).

I created a dummy datagrid - linked to a dataset.
on it are 3 columns:

date, combobox, checkbox

now...go to a current record and click the comobo box and drop down to a new
item in the list.
selecting that list, the record goes into 'edit mode ( left pencil in the
datagrid view ).

Now if I hit my 'save' button right now, it doesnt actaully save that
change.
It will save it if I hit 'enter' or 'tab' first. ( Pencil turns back to
black arrow )

Is this normal of a .net datagrid ?
Is there anyway around it - some code i can put somewhere so i dont click a
dropdown, and hit save right away, but really I havnt changed the field
column yet until I hit the enter key or tab key or click to another field /
column / record.

Hope that makes sense.

Thanks

Miro
 
Found it - i think

I must put this code wherever I want it to take the current input ( still in
edit mode ) of a cell.

DataGrid.endedit()

Miro
 
And as well to finish off this post I had to add this:

BindingContext(MyBindingSource).EndCurrentEdit()
to keep the last 'added' line to the binding source as well.

Im still trying to read up on 'BindingContext' on what it actually does but
those two lines of code did the trick for me.

Cheers' - sorry for all the posts.

Miro
 
Miro,

I thought the latter was not anymore necessary in versions behind 2003,
endedit should be enough.

Cor
 
You are correct (it worked with the first line)- but I had to add that so
when the datagridview automatically adds the next row - it stays as well.

Hard to know what to google for when you dont know what to google for :)

I found the first line
DataGrid.endedit()
allowed the changed cell to stay...

and this line:
BindingContext(MyBindingSource).EndCurrentEdit()
Kept the automatic line added by automatic addrows in the datagrid when a
save was done.

Cheers'

Miro
 
Back
Top