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. Windows Forms
  4. DataGridView Custom Cells/Columns problems

DataGridView Custom Cells/Columns problems

Scheduled Pinned Locked Moved Windows Forms
csharpcssvisual-studiotesting
3 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.
  • K Offline
    K Offline
    kmh72756
    wrote on last edited by
    #1

    I believe that my questions are all going to revolve around the internal workings of DataGridView. I've been trying to find a forum where I can get some interaction and help to move forward. Microsoft's websites seem to be all questions and no answers. I'm using VB.Net under Visual Studio 2005 SP2. I need to have a DataColumn that is dynamically visible based on other data in the same DataRow. After a lot of unsuccessful testing with various methods of accomplishing this, I came across the concept of Custom Cells/Columns. I started with several slightly varying examples and everything seemed to be falling into place. I tried to research each property and attribute as I incrementally learned a lot about the internal workings of Windows controls in general and DataGridView in particular. The confusing symptom is that as I scroll down through the grid, the painting of the custom cells is at best unreliable. I created a minimum test case to eliminate as many variables as possible and I combined all of the source into one Form1.vb as follows:

    Option Explicit On
    Option Strict On
    Public Class Form1
    Public m_OrderDetails As Generic.List(Of OrderDetail)
    Public m_dgv As New System.Windows.Forms.DataGridView

    Public Enum GridViewColumnType
    TextBox
    InvisibleTextBox
    End Enum

    Public Sub New()
    MyBase.New()
    InitializeComponent()
    ' fake the usual load procedures with minimum so this screen can stand alone
    m_OrderDetails = New Generic.List(Of OrderDetail)
    Dim LineCounter As Int32 = 0
    Dim ItemCounter As Int32 = 0
    GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
    GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.ItemCodes)
    GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
    GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Dollars)
    GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
    GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.ItemCodes)
    GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
    End Sub

    Private Sub GenerateSetOfLines(ByRef linecount As Int32, ByRef itemcount As Int32, ByVal splittype As OrderDetail.ProductItemDealerSplitType)
    itemcount += 1
    linecount += 100
    Dim od As New OrderDetail(linecount, "ITEM" & item

    L 1 Reply Last reply
    0
    • K kmh72756

      I believe that my questions are all going to revolve around the internal workings of DataGridView. I've been trying to find a forum where I can get some interaction and help to move forward. Microsoft's websites seem to be all questions and no answers. I'm using VB.Net under Visual Studio 2005 SP2. I need to have a DataColumn that is dynamically visible based on other data in the same DataRow. After a lot of unsuccessful testing with various methods of accomplishing this, I came across the concept of Custom Cells/Columns. I started with several slightly varying examples and everything seemed to be falling into place. I tried to research each property and attribute as I incrementally learned a lot about the internal workings of Windows controls in general and DataGridView in particular. The confusing symptom is that as I scroll down through the grid, the painting of the custom cells is at best unreliable. I created a minimum test case to eliminate as many variables as possible and I combined all of the source into one Form1.vb as follows:

      Option Explicit On
      Option Strict On
      Public Class Form1
      Public m_OrderDetails As Generic.List(Of OrderDetail)
      Public m_dgv As New System.Windows.Forms.DataGridView

      Public Enum GridViewColumnType
      TextBox
      InvisibleTextBox
      End Enum

      Public Sub New()
      MyBase.New()
      InitializeComponent()
      ' fake the usual load procedures with minimum so this screen can stand alone
      m_OrderDetails = New Generic.List(Of OrderDetail)
      Dim LineCounter As Int32 = 0
      Dim ItemCounter As Int32 = 0
      GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
      GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.ItemCodes)
      GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
      GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Dollars)
      GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
      GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.ItemCodes)
      GenerateSetOfLines(LineCounter, ItemCounter, OrderDetail.ProductItemDealerSplitType.Percent)
      End Sub

      Private Sub GenerateSetOfLines(ByRef linecount As Int32, ByRef itemcount As Int32, ByVal splittype As OrderDetail.ProductItemDealerSplitType)
      itemcount += 1
      linecount += 100
      Dim od As New OrderDetail(linecount, "ITEM" & item

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I do not read whole your question. But by reading some lines what I got is that you need to make visibility true or false for particular column of DataGrid based on some condition or data change in particular row of the same grid. Find following code useful for the same.

      //for making visibility true or false, just try this code.
      dataGridView1.Columns["column_name"/column_number].Visible = false/true;

      //To access particular cell, you need to track cell content click event
      //In that you can access particular cell by e.RowIndex and e.ColumnIndex
      //So you will get value of clicked cell and based on value of it you can
      //make particular column visible on or off as described in above code.
      private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
      {
      String str=dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
      }

      HTH

      Jinal Desai - LIVE Experience is mother of sage....

      K 1 Reply Last reply
      0
      • L Lost User

        I do not read whole your question. But by reading some lines what I got is that you need to make visibility true or false for particular column of DataGrid based on some condition or data change in particular row of the same grid. Find following code useful for the same.

        //for making visibility true or false, just try this code.
        dataGridView1.Columns["column_name"/column_number].Visible = false/true;

        //To access particular cell, you need to track cell content click event
        //In that you can access particular cell by e.RowIndex and e.ColumnIndex
        //So you will get value of clicked cell and based on value of it you can
        //make particular column visible on or off as described in above code.
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
        String str=dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
        }

        HTH

        Jinal Desai - LIVE Experience is mother of sage....

        K Offline
        K Offline
        kmh72756
        wrote on last edited by
        #3

        I'm sorry that you feel the need to reply to messages without reading them. As I said, I've had a lot of unsuccessful testing with various methods of accomplishing dynamic visibility of cells. Your suggestion is just one of a half dozen that I already desperately tried. It does NOT work. It hides an entire column. I really need an answer to my current situation for which I believe I have provided an entire independent functioning example. :zzz:

        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