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. .NET (Core and Framework)
  4. DataGridView In Form Designer

DataGridView In Form Designer

Scheduled Pinned Locked Moved .NET (Core and Framework)
questionvisual-studio
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
    junxian_chen
    wrote on last edited by
    #1

    Hi ! I have created a form designer from different examples I found here or elsewhere. But I have a trouble when I try to edit a DataGridView: "Edit columns" and "Add columns" automatically appear in my PropertyGrid, and I can click to show the "classic" VS Datagridview column editor. The trouble is that when I "Add" a column, no type is available, so when I click "Add", a exception is launched... As this column editor is launched "automatically", how can I extend it to add types in the Add window ? Looking forward to hearing from someone ;-) Best regards junxian

    T 1 Reply Last reply
    0
    • J junxian_chen

      Hi ! I have created a form designer from different examples I found here or elsewhere. But I have a trouble when I try to edit a DataGridView: "Edit columns" and "Add columns" automatically appear in my PropertyGrid, and I can click to show the "classic" VS Datagridview column editor. The trouble is that when I "Add" a column, no type is available, so when I click "Add", a exception is launched... As this column editor is launched "automatically", how can I extend it to add types in the Add window ? Looking forward to hearing from someone ;-) Best regards junxian

      T Offline
      T Offline
      Tal Kain
      wrote on last edited by
      #2

      The easiest way I know to work with a DataGridView is to create a DataTable… create its columns and then connect the DataTable to the DataGridView as its data source.. I created an empty form and throwed a DataGridView on it with the name "gridNumbers" here is the code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace DataGridExample { public partial class frmMain : Form { DataTable oTable; public frmMain() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { oTable = new DataTable(); oTable.Columns.Add("Number", typeof(int)); //with cell's type.. oTable.Columns.Add("Text"); //a simple way.. gridNumbers.DataSource = oTable; //connecting the table to the grid AddRow(1, "One"); AddRow(2, "Two"); AddRow(3, "Three"); AddRow(4, "Four"); } protected void AddRow(int num, string text) { DataRow oRow = oTable.NewRow(); //getting a row with the table's scheme oRow["Number"] = num; oRow["Text"] = text; oTable.Rows.Add(oRow); } } } I tried to make this example as clear as possible... hope you got your answer :-)

      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