Hi,
"Eve" <(E-Mail Removed)> wrote in message
news:3CC3A5A3-ADD4-46C2-95FC-(E-Mail Removed)...
> How do I bind my DataView to my DataGridView control? Here's the scenario:
> because I want to make my first column a check box, I have defined a
> collection for my data grid in the designer. I also had to specify the
> columns for my dataTable (see code below). After I did that, there were 8
> columns displayed in the grid (the first 4 from my collection (they were
> empty) and the last 4 populated with the DataView data). I set the grid's
> AutoGenerateColumns property to False so that I see only 4 columns (those
> defined in the collection) instead of 8, but how do I get them populated
> witht the DataView data? dgvTables.DataSource = myDataView doesn't do the
> trick, I don't know what I'm doing wrong.
>
> dgvTables.AutoGenerateColumns = False
> Dim dt As New DataTable
> dt.Columns.AddRange(New DataColumn(3) {New DataColumn("Copy"), New
> DataColumn("Source Table"), New DataColumn("Destination Table"), New
> DataColumn("Columns")})
> ...
> Dim dr1 As DataRow = dt.NewRow
> ...
> dr1.ItemArray = New Object(2) {checked, table.Name, table.Name} ' NOTE:
> checked can be either "T" or "F"
> ...
> dt.Rows.Add(dr1)
> ...
> Dim myDataView As DataView
> myDataView = New DataView(dt)
> myDataView.Sort = ""
> dgvTables.DataSource = myDataView
> dgvTables.Refresh()
If i understand it correctly, then you need to set a DataPropertyName on
each DataGridViewColumn (using column editor or from code), which maps to
each column name in the DataTable/DataView.
HTH,
Greetings
|