Simple Datagrid question

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
 
M

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
 
M

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
 
C

Cor Ligthert[MVP]

Miro,

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

Cor
 
M

Miro

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

datagrid question 1
DataGrid 1
Simple Datagrid question... 1
Datagrid and money format problems (BUG?) 2
Update SQL Table Data using DataGrid 1
EndEdit not working 2
Datagrid | Capture Key Down event 1
Datagrid 2

Top