DataGrid/SqlCeDataAdapter Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Folks,

I have a DataGrid I've populated from a SqlCeDataAdapter. The DataGrid lives
on a Form, from which it is possible to get to a second Form allowing
creation of a new record in the table from which the SqlCeDataAdapter reads
(selects). When I close the second Form, I want the new record to appear in
the DataGrid. I can make this happen by clearing and re-filling (from the
adapter) the table which is the DataSource for the DataGrid, but I was
wondering if this is the correct approach. Should I use
SqlCeDataAdapter.InsertCommand and SqlCeDataAdapter.Update, instead?

A second, unrelated, question is, is it possible to configure the DataGrid
so that only an entire row can be selected, rather than individual cells?

Thanks,

Matthew Fleming
 
On your first question, I would not use a SqlCeDataAdapter but rather
fill a DataTable with the initial rows to display, set the DataGrid's
datasource
equal to that DataTable, add rows to the DataTable (updating the underlying
SQLCE DB with insert or update statements as needed), etc. To refresh the
DataGrid, just reset it's datasource equal to the DataTable as the DataTable
changes. The SqlCeDataAdapter will not always generate usable insert
and update commands and this is a slow performing option for any signifncant
number of records.

Second, you simply respond to the MouseUp event on the DataGrid, inspect the
HitTestType to determine if a cell or row header has been selected, then
select
the entire row in code.
--
Darren Shaffer
..NET Compact Framework MVP
Principal Architect
Connected Innovation
www.connectedinnovation.com
 
Back
Top