Problems with VB.NET Datagrid

S

simchajoy2000

Hi,

I have been working with datagrids a lot in the past two weeks and I
am running across a lot of problems. Maybe there is no way around
these problems but I hope there are and someone out there can advise
me on how to do it.

1. The biggest problem I am finding is that the datagrid does not
update the datagrid.datasource very well. When a new row is created
in the datagrid it may or may not be created in the datasource as
well. When the rows are sorted in the datagrid, the datasource has no
idea what the new structure is. These inconsistencies are causing me
a lot of problems in the code I am trying to run behind the scenes.

2. I am also attempting to use combo box style columns in my datagrid
and this is just a mess. My code works great unless users try to use
certain features the datagrid object makes possible - such as the
escape key to go back to previously entered information - even when
the datagrid remembers this old information, I can't get my combo
boxes to remember and retain this value when the user clicks away.
Has anyone successfully used combo box columns in their datagrids and
eliminated these kinds of errors??

Any advice would be greatly appreciated!! Thanks!!

Joy
 
J

jim

Hi Joy,

1a. in order to propagate the new row to the datagrid you need to ensure
that the DataGrid.EndEdit() call is made. Typically you can ensure this
happens by moving either up a row or down a row while the grid has the
focus, or clicking on another row in the grid. In this scenario, the grid
calls the EndEdit on the particular row for you... the problem with this is
that if you only have a single row, you can't move up or down, and if you
just click off of the grid to say click a button to update back to the
database, the EndEdit doesn't seem to get called.

How I hande this is by making sure to call the EndEdit method of the
datagrid and the EndEdit method of the datarow that was last being edited.

1b. to get the current row that is selected in the grid you use the binding
context and the currencymanager to get it. ex.

ctype(myDatagrid.BindingContext(myGridsDataSource).Current, DataRowView).Row
(forgive and misspells or mistypes, it's late!)

this will give you the currently selected row in the grid regardless of the
grids current sort.

2. I've never implemented a custom grid column style, but i'm not sure which
code you're using in particular. i know that there is a good one on
Syncfusions Windows Forms Faq. I'm not sure of the url offhand, but if you
just do a search for "syncfusion windows forms faq" in this group you should
come up with a million hits...

hope this helps.

good luck,

jim
 
C

Cor Ligthert

Joy,

To overcome your problem with the datagridupdate set somewhere before the
update this one

BindingContext(TheDatagridDatasource).EndCurrentEdit()

For a combobox in a datagrid I made a sample using the Syncfusion simple
sample which I updated by the way to let it go with early binding.

http://www.google.com/[email protected]

I hope this helps?

Cor
 
J

Joy Labadie

Thank you so much for all the help!! I was able to use many of your
suggestions to resolve most of my issues.

However, I am still encountering some inconsistencies with my combo box
datagrid columns and I am actually using the code you recommended - the
Syncfusion sample. I am still encountering the problems I mentioned
before in my first posting such as the escape key problem - has anyone
ever resolved this issue??

Joy
 

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

Top