Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DataGridView Binding - Need to Skip Some Columns

DataGridView Binding - Need to Skip Some Columns

Scheduled Pinned Locked Moved C#
wpfwcfquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mwith
    wrote on last edited by
    #1

    Hi, I have an instance of data table named Bank_Details with the columns "Bank_Code, Name, Acc_No", sitting inside a dataset MyDataSet. I have a BindingSource associated to the MyDataSet/Bank_Details. Without creating another instance of the table, I want to bind it to a datagridview, and only have Bank_Code column show up in the DataGridView. One way I know I can do it is to do a Visible=false on DataBindingComplete event for columns that I don't want displayed. But I am trying to avoid all that unnecessary adding of columns and hiding them when my requirement is to not deal with those columns at all. Just wondering if there is a way to bind a DataGridView to an already available instance of a DataTable and limit the databinding to only specific columns? I appreciate you all sharing any insights regarding this.

    D J 2 Replies Last reply
    0
    • M mwith

      Hi, I have an instance of data table named Bank_Details with the columns "Bank_Code, Name, Acc_No", sitting inside a dataset MyDataSet. I have a BindingSource associated to the MyDataSet/Bank_Details. Without creating another instance of the table, I want to bind it to a datagridview, and only have Bank_Code column show up in the DataGridView. One way I know I can do it is to do a Visible=false on DataBindingComplete event for columns that I don't want displayed. But I am trying to avoid all that unnecessary adding of columns and hiding them when my requirement is to not deal with those columns at all. Just wondering if there is a way to bind a DataGridView to an already available instance of a DataTable and limit the databinding to only specific columns? I appreciate you all sharing any insights regarding this.

      D Offline
      D Offline
      Drew McGhie
      wrote on last edited by
      #2

      I've encountered this as well. If there is a solution that someone else has found that works better, by all means use it, but here's the workaround that I've used: What I have done to get around this is to manually enter all the columns into the DataGridView in the forms designer, and set the "DataPropertyName" property on each column to the appropriate DataTable column that will be in the dataset. I can then set the visible on these to false, and bind to them normally, and have only the desired columns show up. What this also allows me to do is use the hidden values in rows for calculations and whatnot, but also set up formatting on the individual cells at design time instead of during runtime. It works for my means (I use DataGrids to display a lot of line-driven real estate calculations and different views on the same value ($/SF/Mo vs $/SF/Yr in unbound columns based on read-only data in visible columns and other data in !visible columns). Hope this helps ##EDIT Edited to be a little more specific

      1 Reply Last reply
      0
      • M mwith

        Hi, I have an instance of data table named Bank_Details with the columns "Bank_Code, Name, Acc_No", sitting inside a dataset MyDataSet. I have a BindingSource associated to the MyDataSet/Bank_Details. Without creating another instance of the table, I want to bind it to a datagridview, and only have Bank_Code column show up in the DataGridView. One way I know I can do it is to do a Visible=false on DataBindingComplete event for columns that I don't want displayed. But I am trying to avoid all that unnecessary adding of columns and hiding them when my requirement is to not deal with those columns at all. Just wondering if there is a way to bind a DataGridView to an already available instance of a DataTable and limit the databinding to only specific columns? I appreciate you all sharing any insights regarding this.

        J Offline
        J Offline
        JoeRip
        wrote on last edited by
        #3

        Are you actually adding the columns one by one? Or are you just doing: myDataGridView.DataSource = myDataTable I haven't looked at it yet, but couldn't you actually just do: myDataGridView.DataSource = myDataTable.Columns[x], to only show that one column?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups