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. Simple example of DataGridView..?

Simple example of DataGridView..?

Scheduled Pinned Locked Moved C#
databasehelptutorialquestion
2 Posts 2 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.
  • J Offline
    J Offline
    JamesParsons
    wrote on last edited by
    #1

    Hello, I'm hoping someone can help me out here. I want to get started using DataGridView, but I've not actually managed to find any examples that fit what I'm trying to do. What I want to do is very simple: (1) I have a list of class instances thus: List<MyClass> classList = new List<MyClass>(); classList.Add(new MyClass("Fred")); classList.Add(new MyClass("Wilma")); etc (2) I want each MyClass member of classList to be represented as a row in my DataGridView (3) I want to show only a subset of the class parameters, for example: public class MyClass { private string name; private string desc; private int anumber; // Want to show these in the interface public String Name { get { return (name); } set { name = value; } } public String Description { get { return (desc); } set { desc = value; } } // etc.. // I DON'T want to show this in the interface public int Number { get { return (anumber); } set { anumber= value; } } } I understand that I need to set the DataSource parameter of my DataGridView to my data, in some way, but I don't seem to be able to get it to work. Do I need to do something to my classes to get it to work? I think that sums it up. No SQL, nothing just a nice list of data that I want to display. Can anyone help? Many thanks!! :)

    K 1 Reply Last reply
    0
    • J JamesParsons

      Hello, I'm hoping someone can help me out here. I want to get started using DataGridView, but I've not actually managed to find any examples that fit what I'm trying to do. What I want to do is very simple: (1) I have a list of class instances thus: List<MyClass> classList = new List<MyClass>(); classList.Add(new MyClass("Fred")); classList.Add(new MyClass("Wilma")); etc (2) I want each MyClass member of classList to be represented as a row in my DataGridView (3) I want to show only a subset of the class parameters, for example: public class MyClass { private string name; private string desc; private int anumber; // Want to show these in the interface public String Name { get { return (name); } set { name = value; } } public String Description { get { return (desc); } set { desc = value; } } // etc.. // I DON'T want to show this in the interface public int Number { get { return (anumber); } set { anumber= value; } } } I understand that I need to set the DataSource parameter of my DataGridView to my data, in some way, but I don't seem to be able to get it to work. Do I need to do something to my classes to get it to work? I think that sums it up. No SQL, nothing just a nice list of data that I want to display. Can anyone help? Many thanks!! :)

      K Offline
      K Offline
      Kodanda Pani
      wrote on last edited by
      #2

      Hi, Use a binding source to bind your list and then bind the binding source to the data grid view. dataGridView1.DataSource = bindingSource1; dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader); this.bindingSource1.DataSource = myList; Thanks and Regards Mahen

      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