Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / November 2006

Tip: Looking for answers? Try searching our database.

DataView to DataGridView binding problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eve - 13 Nov 2006 17:12 GMT
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()
Bart Mermuys - 13 Nov 2006 19:40 GMT
Hi,

> 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
[quoted text clipped - 25 lines]
> 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
Eve - 13 Nov 2006 20:13 GMT
It worked. Thank you very much!!!

> Hi,
>
[quoted text clipped - 34 lines]
> HTH,
> Greetings

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.