jeudi 23 novembre 2023

C# Allow user to use checkbox column to select one row in each DataGridView on a form

I am new to C# and Visual Studio and am building a application which interacts with data.

I am trying to get my head around the intricacies of DataGridView controls.

I'm basically trying to build a "mapping" interface whereby an user can map a column from one table to a column in another table (in a different database).

I have two DataGridView controls on a form, one for each of the 2 databases being interacted with. Each DataGridView is populated using a SqlDataAdapter and DataTable, which is triggered by selecting a table name from a corresponding combo box.

The corresponding grid displays the column name and datatype of each column in a data table.

So essentially the user will have 2 grids showing the columns of a table from each of the 2 databases.

I have added a checkbox column to each DataGridView, and so the user can only select one row from each data grid I have set the VirtualMode property of each grid to "True".

However, at runtime, the checkbox column in both grids is behaving like a set of Radio buttons, thus only allowing the user to select ONE checkbox across both grids.

Is there any way I can remove this limitation?

The mapping aspect of the work I'm trying to do is going to be difficult, but if I can't get around this, I'm going to have to re-think my approach. I was basically going to try, one at a time, to build a SQL INSERT INTO statement through code so I'd end up with something like

INSERT INTO TargetDB.dbo.TargetTable (TargetFieldA, TargetFieldB, TargetFieldC) 
SELECT SrcFieldA AS TargetFieldA, SrcFieldB AS TargetFieldB, SrcFieldC AS TargetFieldC FROM SourceDB.dbo.SourceTable 
EXCEPT 
SELECT TargetFieldA, TargetFieldB, TargetFieldC FROM TargetDB.dbo.TargetTable;

But that's probably for another question. As I said, I'm very new to C# so am probably approaching this all wrong anyway.

I haven't written any code yet to get around this as I was hoping I was just overlooking a setting or something. The only thing I have tried is placing each DataGridView control inside its own Panel, as I do with Radio buttons to ensure they "group" together and are not affected by the checked property of a radio button outside the panel. But that didn't work.

Many thanks in advance.

Regards

Steve




Aucun commentaire:

Enregistrer un commentaire