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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Windows Form DataGrid

Windows Form DataGrid

Scheduled Pinned Locked Moved C#
tutorialquestionwinforms
6 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.
  • D Offline
    D Offline
    devvvy
    wrote on last edited by
    #1

    Hi, working with DataGrid on a Windows Form right now. Three questions: Q1: It seems that Windows Forms DataGrid doesn't support paging as they do on WebForms. Q2: How can I disable editing on cell(s)/rows belonging to a particular column? Q3: Any good tutorial on how to embed controls in Windows Form DataGrid? Controls like buttons and other stuff...etc. With WebForms' DataGrid, it's done by . How can we do the same here on Windows Form? With "Checkbox", just feed in a column of type "bool", simple. But with other types? Buttons, links... Thanks a bunch. norm

    A 1 Reply Last reply
    0
    • D devvvy

      Hi, working with DataGrid on a Windows Form right now. Three questions: Q1: It seems that Windows Forms DataGrid doesn't support paging as they do on WebForms. Q2: How can I disable editing on cell(s)/rows belonging to a particular column? Q3: Any good tutorial on how to embed controls in Windows Form DataGrid? Controls like buttons and other stuff...etc. With WebForms' DataGrid, it's done by . How can we do the same here on Windows Form? With "Checkbox", just feed in a column of type "bool", simple. But with other types? Buttons, links... Thanks a bunch. norm

      A Offline
      A Offline
      ankita patel 0
      wrote on last edited by
      #2

      Q2: How can I disable editing on cell(s)/rows belonging to a particular column? http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridcolumnstyleclassreadonlytopic.asp Q3: Any good tutorial on how to embed controls in Windows Form DataGrid? Controls like buttons and other stuff...etc. With WebForms' DataGrid, it's done by . How can we do the same here on Windows Form? With "Checkbox", just feed in a column of type "bool", simple. But with other types? Buttons, links... http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridclasstopic.asp

      D 1 Reply Last reply
      0
      • A ankita patel 0

        Q2: How can I disable editing on cell(s)/rows belonging to a particular column? http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridcolumnstyleclassreadonlytopic.asp Q3: Any good tutorial on how to embed controls in Windows Form DataGrid? Controls like buttons and other stuff...etc. With WebForms' DataGrid, it's done by . How can we do the same here on Windows Form? With "Checkbox", just feed in a column of type "bool", simple. But with other types? Buttons, links... http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridclasstopic.asp

        D Offline
        D Offline
        devvvy
        wrote on last edited by
        #3

        Thanks for the tip. I got it working now (enabling/disabling in-place editing). It's very convenient - I still remember way back when I was working with MFC. I need to actually draw an editbox and override a whole bunch of events to get this simple functionality. Glad .NET finally arrives. But I don't think the second reference on DataGrid provides much information on embedding controls within DataGrid. norm

        A 1 Reply Last reply
        0
        • D devvvy

          Thanks for the tip. I got it working now (enabling/disabling in-place editing). It's very convenient - I still remember way back when I was working with MFC. I need to actually draw an editbox and override a whole bunch of events to get this simple functionality. Glad .NET finally arrives. But I don't think the second reference on DataGrid provides much information on embedding controls within DataGrid. norm

          A Offline
          A Offline
          ankita patel 0
          wrote on last edited by
          #4

          great, as you could fine answer to one of your questions. :) i am not a c# expert, actually have just started reading c#, but just trying to find answer of the queries asked here, helps me also in improving my knowledge of c#. as far as embedding controls within DataGrid, i couldn't find anyway to do it. if you find the answer, please post it here, i would love to know.

          S 1 Reply Last reply
          0
          • A ankita patel 0

            great, as you could fine answer to one of your questions. :) i am not a c# expert, actually have just started reading c#, but just trying to find answer of the queries asked here, helps me also in improving my knowledge of c#. as far as embedding controls within DataGrid, i couldn't find anyway to do it. if you find the answer, please post it here, i would love to know.

            S Offline
            S Offline
            sumeat
            wrote on last edited by
            #5

            You can show controls in DataGrid, for e.g. showing a button control in a column by adding those controls to the grid. // Create a control Button myButton = new Button(); myButton.Visible = false; // Add the button to the data grid myDataGrid.Controls.Add(myButton); // Now handle the Paint event of the grid OnDataGridPaint(..) { if (myDataGrid.CurrentCell.ColumnNumber = ) { myButton.width = myDataGrid.GetCurrentCellBounds().Width; } } // CurrentCellChange event OnDataGridCurrentCellChangeEvent(..) { if (myDataGrid.CurrentCell.ColumnNumber = ) { myButton.Location = myDataGrid.GetCurrentCellBounds().Location; myButton.Visible = true; } else { myButton.Visible = false; } } // Handle Layout and Scroll events of DataGrids OnDataGridLayout(..) { OnDataGridCurrentCellChangeEvent(); } OnDataGridScrolled(..) { OnDataGridCurrentCellChangeEvent(); } This is just psuedo code. You may have to do some more tweaking for this to work. But this is generally how it is done (or how I have done it!) Hope this helps. Suhas

            D 1 Reply Last reply
            0
            • S sumeat

              You can show controls in DataGrid, for e.g. showing a button control in a column by adding those controls to the grid. // Create a control Button myButton = new Button(); myButton.Visible = false; // Add the button to the data grid myDataGrid.Controls.Add(myButton); // Now handle the Paint event of the grid OnDataGridPaint(..) { if (myDataGrid.CurrentCell.ColumnNumber = ) { myButton.width = myDataGrid.GetCurrentCellBounds().Width; } } // CurrentCellChange event OnDataGridCurrentCellChangeEvent(..) { if (myDataGrid.CurrentCell.ColumnNumber = ) { myButton.Location = myDataGrid.GetCurrentCellBounds().Location; myButton.Visible = true; } else { myButton.Visible = false; } } // Handle Layout and Scroll events of DataGrids OnDataGridLayout(..) { OnDataGridCurrentCellChangeEvent(); } OnDataGridScrolled(..) { OnDataGridCurrentCellChangeEvent(); } This is just psuedo code. You may have to do some more tweaking for this to work. But this is generally how it is done (or how I have done it!) Hope this helps. Suhas

              D Offline
              D Offline
              devvvy
              wrote on last edited by
              #6

              Thanks Suhas, I think I understand what you're getting at. norm

              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