2 Replies - 9275 Views - Last Post: 13 April 2013 - 07:42 AM

#1 mattcash83   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 50
  • Joined: 23-June 12

Filling DataGridView With Data From Access DB

Posted 09 April 2013 - 06:07 PM

I will start off by saying that I do understand how to bind my DataGridView to an Access file. My problem lies in the fact that when I do this, my dgv automatically produces and displays all of the columns from my table. I currently have my dgv designed to hold three columns (one visible, the other two hidden). I need to know if there is a way to specify that I want columnx from my table to fill columnx of my dgv and so on. Should I try a completely different method of filling my dgv?

Is This A Good Question/Topic? 0
  • +

Replies To: Filling DataGridView With Data From Access DB

#2 mattcash83   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 50
  • Joined: 23-June 12

Re: Filling DataGridView With Data From Access DB

Posted 13 April 2013 - 07:07 AM

To answer my question (in case it could help anybody else),

In the case I was presenting,

1. Do not pre-define columns in your datagridview - leave it blank in your design form.

2. Bind your datagridview table to your db table and fill it.

3. AFTER the dgv is bound and filled, write your code to have it display the way you actually want it to:

            datagridview.Columns(1).Visible = False
            datagridview.Columns(2).Visible = False
            datagridview.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill



and so on. It's amazing what actually sleeping during a problem can achieve! Maybe I was the only one running into this wall, but just in case, I hope this helped.


MattCash

This post has been edited by mattcash83: 13 April 2013 - 07:08 AM

Was This Post Helpful? 1
  • +
  • -

#3 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6798
  • View blog
  • Posts: 28,093
  • Joined: 12-December 12

Re: Filling DataGridView With Data From Access DB

Posted 13 April 2013 - 07:42 AM

A similar question arose recently, although not specific to Access. If there are existing columns, and a DataSource assigned, then clearing the columns and setting the DS to Nothing, before assigning the new DS effectively resets the DataGridView:

Private Sub ResetDataGridView()
    dataGridView1.CancelEdit()
    dataGridView1.Columns.Clear()
    dataGridView1.DataSource = Nothing
End Sub

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1