DataGrid and Selected Rows

From: Chris Dunaway (dunawayc_at__lunchmeat_sbcglobal.net)
Date: 02/10/04


Date: Tue, 10 Feb 2004 15:16:16 -0600

I am writing a simple Windows Forms Application that accesses an Access
database. In the form I instantiate a DataTable object. I then read the
contents of a single table in the Access file into this DataTable. This
works as expected.

Next, I instantiate another DataTable and use the .Clone method on the
first to duplicate the structure into this new datatable. The user then
type a search value into a textbox. I then search the first datatable and
if the row is found, I copy it to the second datatable. This all works
fine.

Finally, I have a DataGrid on the form which is bound to the *second*
datatable, the one with the found rows. The DataGrid shows the rows that
were found. This part is working.

Now my question(s) (I'll bet you're glad I'm finally getting to the
point!!):

1. If the user adds a row to the second table by mistake, I want them to
be able to highlight it and delete it from the DataGrid as well as from the
second table. The DataGrid is ReadOnly. I can do this if only a single
row is selected, but how to do it if more than one row is selected? The
CurrentRowIndex property only seems to show a single row index regardless
of the number of indices actually selected.

2. Is there any way to turn multi select off on the grid?

3. How can I iterate through the rows of the grid and see which ones are
selected?

Keep in mind that the DataGrid is not bound to the Access database, it is
bound to a table that only has a few rows that were copied from another
table. My aim here is NOT to change the Access database. I am only using
the second DataTable as a tempory collection of rows.

-- 
Chris
To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.


Relevant Pages

  • Re: !!!Displaying data in grid!!!
    ... > I need to display data in a ... > grid format, and I cannot find a grid control to do ... > dataset and database. ... I used the Datagrid for this. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Datagrid Issues
    ... I subclassed the grid and that seemed to work, ... > a row in the datagrid by clicking on the row header and pressing the Delete ... > call to the database and check a couple things, if the method that calls the ... > message and then I want the row to not be removed from display in the ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Looping through a datagrid
    ... made some fields in the grid editable and want those changes to hit the ... database at the same time with an update button that I have at the bottom of ... but updating from a datagrid I am getting confused. ... > Why would you loop through a data grid? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Update modified Datagrid to Tables
    ... If you already attached the datagrid to the dataset to get the grid ... > The code you gave me is what I used to populate the dataset. ... coded and does not show the full scope of building recordset from database, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: custom class module- in another database
    ... > and the VB_Creatable attribute allows other databases to instantiate objects ... > won't be able to instantiate the object in another database. ... > 'Abs' is the name of a built-in VBA function. ... >> Public Property Let avviso ...
    (microsoft.public.access.modulesdaovba)