I'm in kind of a pickle - I have a project due tonight and suddenly 2 of my datagridviews are acting funky while the others are fine.

I have 2 tables in an sqlce db. the first is books(id, title, copyright) and the next is publisher(id, name, bookid). I'm writing a vb.net frontend to access the data.

I have data bound datagridviews for both tables. Both have their respective ID columns hidden. The publisher dgv uses a combobox cell style to display the book title in the bookid column. So far so good.

I have suddenly run into a problem where if I have clicked in a cell on the books dgv and then click a cell on another row, the title changes to the id value. The publisher dgv also updates to show the id instead of the title.

It sounds to me like there may be a problem with the booktableadapter or bookbindingsource, but I don't know where to start looking for it. I have a 3rd dgv referencing an unrelated table, and it has no problems. The code for both the working and problematic dgvs are the same (only the control names are different).

Suggestions?

Hi,

You should use the Datagridview CellValidating event for this, because this event is fired when the user is done with the typing and leaves the cell.

You can find some information, here.

Thanks for your reply, but I found at least part of the problem.

I'm using tab pages for different functions in this app, and I inadvertently connected a combobox on 1 tab to the same binding source as the datagridview in question which is on another tab. I still have some problems with the combobox not listing values properly, but setting up a new binding source for the combobox fixed the problem with the datagridview.

My problem with the combobox is that on startup, it displays the id of the data row desired instead of the name value retrieved through the foreign key. If I click to show the list of available items for the combobox, it shows the names (as desired), not the ids. There are 3 comboboxes on that tabpage referencing different tables. 1 of them works properly, the other 2 do what I just described. I have compared the settings between the 3, and they all look to be correct.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.