PC Review


Reply
Thread Tools Rate Thread

DataView to DataGridView binding problem

 
 
=?Utf-8?B?RXZl?=
Guest
Posts: n/a
 
      13th Nov 2006
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()
 
Reply With Quote
 
 
 
 
Bart Mermuys
Guest
Posts: n/a
 
      13th Nov 2006
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




 
Reply With Quote
 
=?Utf-8?B?RXZl?=
Guest
Posts: n/a
 
      13th Nov 2006
It worked. Thank you very much!!!

"Bart Mermuys" wrote:

> 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
>
>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGridView binding problem B. Chernick Microsoft Dot NET Framework Forms 4 30th Oct 2008 12:44 PM
DataGridView binding problem with custom collection =?Utf-8?B?U3R1YXJ0?= Microsoft Dot NET 4 23rd Jul 2006 11:54 PM
datacolumn or dataview binding problem bilalso Microsoft C# .NET 1 23rd May 2006 03:10 PM
DataGridView binding problem =?Utf-8?B?TGFycnkgQ2hhcmx0b24=?= Microsoft Dot NET Framework Forms 1 14th May 2006 05:44 PM
problem binding filtered dataview to listbox =?Utf-8?B?cw==?= Microsoft VB .NET 4 22nd Dec 2005 06:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:23 PM.