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. WinForm Datagrid Control

WinForm Datagrid Control

Scheduled Pinned Locked Moved C#
questionlearning
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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    1.I hava Datagrid control in window forms, which bind data from datatable. I don't want to show "id" field, but I think I need it for click event on a certain row in datagrid. How can I hide this field but still can get value from it? 2. How can I specify the column width for each column? Thanks. Beginner

    J 1 Reply Last reply
    0
    • L Lost User

      1.I hava Datagrid control in window forms, which bind data from datatable. I don't want to show "id" field, but I think I need it for click event on a certain row in datagrid. How can I hide this field but still can get value from it? 2. How can I specify the column width for each column? Thanks. Beginner

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      For #1 give this a shot

      // columnIndex must be set to a number.
      int columnIndex = 1;
      // remove the second column
      GridColumnStylesCollection myGridColumns;
      myGridColumns = dataGrid1.TableStyles[0].GridColumnStyles;
      myGridColumns.RemoveAt( columnIndex );

      For #2 there try this block.

      GridColumnStylesCollection myGridColumns;
      myGridColumns = dataGrid.TableStyles[0].GridColumnStyles;

      foreach(DataGridColumnStyle style in myGridColumns)
      {
      // GetColumnWidth takes the header name and returns the width the column should be
      style.Width = GetColumnWidth(style.HeaderName);
      }

      HTH, James Simplicity Rules!

      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