views:

838

answers:

1

Hello,

I have a Master-Detail relationship implemented with two Datagridview controls in c#. The datasources are each connected to a DataTable and the connection is done using a DataRelation. I added a checkbox column using "Add column" of the DataGridviewTask.

I want to achieve that I can use this checkbox to select / unselect a detail row which will then be related to the current master row. The relation between master and detail row should be 1 : 0..1. After selecting a detail row a method should be called which will save the info in a databse table.

At the moment I don't know how to achieve this, I even can't click on the checkbox (it's definitely not readonly), I assume it has something to do with the "DataPropertyName" of the checkbox column, but I don't know to which property I should set it to.

If anybody has an idea how to achieve this scenario (maybe there is even a free datagridview extension) I would really appreciate this.

Thanks Daniel

+1  A: 

For starters you should make sure there exists a boolean column for the checkbox. In a typed dataset you can easily add one using the DatasetDesigner.

Henk Holterman
Hi, thanks for your answer, but I don't want to change the database schema. I just want to use the checkbox in my code as an indicator that a selection exists.
You can add a column to a DataTable that is not in the Db
Henk Holterman
ah, cool, excellent! Do you also know if there is a way to add that new column as a first column and not as a last column, so that I don't have to write code to change the position in the datagridview (I like the checkbox to be the first column) ?
The order of columns is up to the grid, not the table. Use a designer or write the code.
Henk Holterman