Scott said:
There are 3 elements to making this work:
1. The actual data repository (a database?)
2. The in-memory representation of the original data (a dataset)
3. The user interface for the data (the DataGrid).
I think i will disagree with that. (Please correct me if i'm wrong!)
The in-memory representation, is actually an in memory copy. The
difference being, the copy changes, the original does not. And, this
copy is a datatable, not a dataset. A dataset is the container for one
or many datatables, however. (As well as dataviews and datarelations.)
The original data needs to be replicated into the in-memory container (the
DataSet). This is accomplished by calling the .Fill() method of your
DataAdapter.
Which just runs the .SelectCommand command. It would have been *much*
more clear had they named it "ExecuteSelectCommand" or
"SelectCommandResultsInto"
Now, the DataGrid needs to be "connected" to the in-memory data (the
DataSet).
It actually needs to be connacted to the dataview. If connected to the
dataset, it just shows a plus-sign which expands into the availible
dataviews, of which one must be selected to show any data.
Further, connecting it to a dataset leaves those arrows on the caption
bar. Connecting it directly to the dataview, however, does not.
You must set the DataGrid's datasource property so it knows where
to get the data from, but just setting the datasource doesn't actually go
and get any data.
Yep, that confused me at first. Which is when i realized that the
datagrid has absolutely nothing to do with a dataadaptor. A datagrid is
a window into the dataview. A dataview is the resultset of a datatable
(as opposed to the design). A datatable can be filled in many ways. One
way is with a select statement. One way to run a select statement is
via the Fill() command of a dataadaptor.
So, you need to call the DataGrid's DataBind method to
tell the grid to go and look at the data (specified in the DataSource
property) and bind to it.
When it is set it looks. Databind is not needed, as i expreessed
earlier.
If the data in the DataSet ever gets changed in any way, or if you want to
show the existing data in a different way (a different page of data or a
different sorted view of the data), you are going to need to have the
DataGrid "refresh" its representation of that underlying data. Calling
DataBind does just that.
Actually, calling datagrid.refresh does that.
I still see no reason for databind.
Hmm... unless it somehow "watches" it and refreshes for you.
As a note, calling Fill() works both before and after setting the
datagrid's datasource. That is, the FIll() command triggers the
datagrid to refresh. However, using .Expression() does not. If done
before the datasource is set, it shows the modified data, doing it
after the datasource is set, requires a datagrid.refresh for it to be
noticed.
Anyway, i see datagrid.databindings which requires me a to enter a
property name. I am a bit confused over exactly what this is.
BTW, i appreciate the help in clarifying this. I've got to read,
clarify, and test to figure this whole thing out. I'm still a bit
confused.
B.