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. DataGrid and FlexGrid

DataGrid and FlexGrid

Scheduled Pinned Locked Moved C#
csharphelpquestion
4 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.
  • _ Offline
    _ Offline
    _Superman_
    wrote on last edited by
    #1

    I have a VC dialog that hosts a FlexGrid control. The contol has two columns with data. The first column has read only data and is fixed. So it has a 3D edge for each cell that looks like a button. The second column is editable. I'm porting this to C#. In the form I place a DataGrid to display the data. Two things I cannot do with DataGrid. First, I cannot get the 3D edge for the cells in column 1 and second, I cannot stop DataGrid from adding new rows. I just need to edit the contents of column 2 and not add more rows. Can somebody help ? « Superman »

    H 1 Reply Last reply
    0
    • _ _Superman_

      I have a VC dialog that hosts a FlexGrid control. The contol has two columns with data. The first column has read only data and is fixed. So it has a 3D edge for each cell that looks like a button. The second column is editable. I'm porting this to C#. In the form I place a DataGrid to display the data. Two things I cannot do with DataGrid. First, I cannot get the 3D edge for the cells in column 1 and second, I cannot stop DataGrid from adding new rows. I just need to edit the contents of column 2 and not add more rows. Can somebody help ? « Superman »

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      To create custom columns, extend the DataGridColumnStyle and override the necessary methods. You could then paint whatever borders you want. There are many examples here on CodeProject, MSDN[^], and elsewhere (just google). To disallow new rows, you either need to bind to an IList or IListSource implementation that is fixed in size (like an array of objects), or bind to a DataView instead of a DataSet or DataTable. Set the DataView.AllowNew property to true when doing so. See the documentation for the DataView class for more information and example code.

      Microsoft MVP, Visual C# My Articles

      _ 1 Reply Last reply
      0
      • H Heath Stewart

        To create custom columns, extend the DataGridColumnStyle and override the necessary methods. You could then paint whatever borders you want. There are many examples here on CodeProject, MSDN[^], and elsewhere (just google). To disallow new rows, you either need to bind to an IList or IListSource implementation that is fixed in size (like an array of objects), or bind to a DataView instead of a DataSet or DataTable. Set the DataView.AllowNew property to true when doing so. See the documentation for the DataView class for more information and example code.

        Microsoft MVP, Visual C# My Articles

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        Thanks Heath for you earlier reply. I could get what I wanted done. But I have another problem and thought maybe you could shed some light. The grid has 2 columns and 5 rows out of which one column is editable. I'm implementing an observer pattern where the grid is one of the views. When the user changes the text in the grid column I need to update the model. For this I register for the LostFocus event of the TextBox hosted in the DataGridTextBoxColumn. This is done in my derived class. Everything is allright if the user enters text and changes focus using the mouse. But using the arrow keys, the focus does change to the next grid cell, but there is no LostFocus event generated. « Superman »

        H 1 Reply Last reply
        0
        • _ _Superman_

          Thanks Heath for you earlier reply. I could get what I wanted done. But I have another problem and thought maybe you could shed some light. The grid has 2 columns and 5 rows out of which one column is editable. I'm implementing an observer pattern where the grid is one of the views. When the user changes the text in the grid column I need to update the model. For this I register for the LostFocus event of the TextBox hosted in the DataGridTextBoxColumn. This is done in my derived class. Everything is allright if the user enters text and changes focus using the mouse. But using the arrow keys, the focus does change to the next grid cell, but there is no LostFocus event generated. « Superman »

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          When deriving your own classes, you can fire all the events you want. The Commit method is still called on the derived class so add an event to your class and fire it inside the Commit implementation. It's your class - you have control of what happens.

          Microsoft MVP, Visual C# My Articles

          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