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. Visual Basic
  4. Making a particular cell of datagrids uneditable [modified]

Making a particular cell of datagrids uneditable [modified]

Scheduled Pinned Locked Moved Visual Basic
helpquestion
11 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.
  • H hsprasain

    Hey all: Can anybody give me ideas how can I lock the particular cell of the datagrids. I used Readonly properties of Datagrids, that makes whole datagrids uneditable. I want only some particular cells of grids to be uneditable. Thanks many for your advance help. -- modified at 11:51 Friday 6th July, 2007

    A Offline
    A Offline
    aphei
    wrote on last edited by
    #2

    you can try this code first you must set your grid readonly property to false Dim intI, intJ As Integer With grid For intI = 0 To .Rows.Count - 1 .Rows(intI).ReadOnly = True if intI = x then .Rows(intI).ReadOnly = False For intJ = 0 To .Columns.Count - 1 if intJ = y then .Columns(intJ).ReadOnly = False end if Next End If Next End With hope this can help to solve your problem

    H 1 Reply Last reply
    0
    • H hsprasain

      Hey all: Can anybody give me ideas how can I lock the particular cell of the datagrids. I used Readonly properties of Datagrids, that makes whole datagrids uneditable. I want only some particular cells of grids to be uneditable. Thanks many for your advance help. -- modified at 11:51 Friday 6th July, 2007

      J Offline
      J Offline
      Johan Hakkesteegt
      wrote on last edited by
      #3

      Assuming that your datagrid is bound to a dataset, you can simply use the readonly property of the dataset's columns instead of that of the entire datagrid: MyDataSet.Tables("MyTableName").Columns("MyColumnName").ReadOnly = False 'or True MyDataGrid.DataSource = MyDataSet MyDataGrid.DataMember = "MyTableName" Good luck, Johan

      My advice is free, and you may get what you paid for.

      H 1 Reply Last reply
      0
      • A aphei

        you can try this code first you must set your grid readonly property to false Dim intI, intJ As Integer With grid For intI = 0 To .Rows.Count - 1 .Rows(intI).ReadOnly = True if intI = x then .Rows(intI).ReadOnly = False For intJ = 0 To .Columns.Count - 1 if intJ = y then .Columns(intJ).ReadOnly = False end if Next End If Next End With hope this can help to solve your problem

        H Offline
        H Offline
        hsprasain
        wrote on last edited by
        #4

        Hey: I'm using VB.NET 2003. I didn't find Datagrid1.Rows.count and Datgrids1.Columns.Readonly and ... features. Can you help me how can add those features to grids to run your code? Thanks for your help in advance.

        1 Reply Last reply
        0
        • J Johan Hakkesteegt

          Assuming that your datagrid is bound to a dataset, you can simply use the readonly property of the dataset's columns instead of that of the entire datagrid: MyDataSet.Tables("MyTableName").Columns("MyColumnName").ReadOnly = False 'or True MyDataGrid.DataSource = MyDataSet MyDataGrid.DataMember = "MyTableName" Good luck, Johan

          My advice is free, and you may get what you paid for.

          H Offline
          H Offline
          hsprasain
          wrote on last edited by
          #5

          Hey thanks a lot! I also thought in similar way that you thought. I still got some weird problems. I'm not allow to make the whole column unediatable. I can make only some of the cells of the column. I'd appreciate if you could give me an idea how I can make a praticular cell unediatable rather than by whole coulumn. I'm sorry for my unclear questions last time. Thanks many for your help in advance

          J 1 Reply Last reply
          0
          • H hsprasain

            Hey thanks a lot! I also thought in similar way that you thought. I still got some weird problems. I'm not allow to make the whole column unediatable. I can make only some of the cells of the column. I'd appreciate if you could give me an idea how I can make a praticular cell unediatable rather than by whole coulumn. I'm sorry for my unclear questions last time. Thanks many for your help in advance

            J Offline
            J Offline
            Johan Hakkesteegt
            wrote on last edited by
            #6

            As far as I know, I am afraid you will have to make a choice; by the same principle you can determine the row index and make the row read only. So either make the entire row, or else the entire column read only (or the other way around). I have never tried myself, but perhaps you could investigate the possibility to determine the selected cell and try to make only that cell read only. Another thing you could try is to make all rows read only, then when a user selects a row, make only that row editable, and during the same event make all columns except the selected cell's column read only again. I have no idea though whether this would actually work... Good luck with it, Johan

            My advice is free, and you may get what you paid for.

            H 1 Reply Last reply
            0
            • J Johan Hakkesteegt

              As far as I know, I am afraid you will have to make a choice; by the same principle you can determine the row index and make the row read only. So either make the entire row, or else the entire column read only (or the other way around). I have never tried myself, but perhaps you could investigate the possibility to determine the selected cell and try to make only that cell read only. Another thing you could try is to make all rows read only, then when a user selects a row, make only that row editable, and during the same event make all columns except the selected cell's column read only again. I have no idea though whether this would actually work... Good luck with it, Johan

              My advice is free, and you may get what you paid for.

              H Offline
              H Offline
              hsprasain
              wrote on last edited by
              #7

              Hey Johan: Thanks a lot for good advice. Unfortunately, I was unable make a particular row uneditable. Below is my code. Public Function CreateData(ByVal row As Integer, ByVal col As Integer) dt = New DataTable("sublayers") Dim i, j, k As Integer ' col is used for determing column headers. dt.Columns.Add(New DataColumn("Sublayer No", GetType(String))) dt.Columns.Add(New DataColumn("Material Set No", GetType(String))) dt.Columns.Add(New DataColumn("Thickness (m)", GetType(String))) dt.Columns(2).ReadOnly = True For i = 1 To row dr = dt.NewRow() For j = 0 To col - 1 dr(j) = " " Next dt.Rows.Add(dr) Next i 'creating a datase Dim ds As New DataSet ds = New DataSet ds.Tables.Add(dt) 'adding the table to dataset DataGrid1.SetDataBinding(ds, "sublayers") I'm using this function to dynamically create datagrids. I neber got options to make rows uneditable. Can you advise how shall do this. Thanks a lot for your help.

              J 1 Reply Last reply
              0
              • H hsprasain

                Hey Johan: Thanks a lot for good advice. Unfortunately, I was unable make a particular row uneditable. Below is my code. Public Function CreateData(ByVal row As Integer, ByVal col As Integer) dt = New DataTable("sublayers") Dim i, j, k As Integer ' col is used for determing column headers. dt.Columns.Add(New DataColumn("Sublayer No", GetType(String))) dt.Columns.Add(New DataColumn("Material Set No", GetType(String))) dt.Columns.Add(New DataColumn("Thickness (m)", GetType(String))) dt.Columns(2).ReadOnly = True For i = 1 To row dr = dt.NewRow() For j = 0 To col - 1 dr(j) = " " Next dt.Rows.Add(dr) Next i 'creating a datase Dim ds As New DataSet ds = New DataSet ds.Tables.Add(dt) 'adding the table to dataset DataGrid1.SetDataBinding(ds, "sublayers") I'm using this function to dynamically create datagrids. I neber got options to make rows uneditable. Can you advise how shall do this. Thanks a lot for your help.

                J Offline
                J Offline
                Johan Hakkesteegt
                wrote on last edited by
                #8

                Hi, My apologies, I misinformed you. I just mistakenly assumed there would be, but you are right, there isn't any direct option to make a row readonly. The next option that comes to mind (and I don't see any alternatives), if you really need to lock only certain cells, is to set the readonly property of the datagrid to true, and bind the data from the selected datarow to regular textboxes or some other input system. This will allow you to control the input more easily, and to simply enable or disable a textbox when certain criteria are met. Hope it helps, Johan

                My advice is free, and you may get what you paid for.

                H 1 Reply Last reply
                0
                • J Johan Hakkesteegt

                  Hi, My apologies, I misinformed you. I just mistakenly assumed there would be, but you are right, there isn't any direct option to make a row readonly. The next option that comes to mind (and I don't see any alternatives), if you really need to lock only certain cells, is to set the readonly property of the datagrid to true, and bind the data from the selected datarow to regular textboxes or some other input system. This will allow you to control the input more easily, and to simply enable or disable a textbox when certain criteria are met. Hope it helps, Johan

                  My advice is free, and you may get what you paid for.

                  H Offline
                  H Offline
                  hsprasain
                  wrote on last edited by
                  #9

                  Hey: Thanks a lot: I appreciate your time and help. I think I should think of making custom Datagrid control to add readonly features for each cell. Do you have any ideas how shall I do that?

                  J 1 Reply Last reply
                  0
                  • H hsprasain

                    Hey: Thanks a lot: I appreciate your time and help. I think I should think of making custom Datagrid control to add readonly features for each cell. Do you have any ideas how shall I do that?

                    J Offline
                    J Offline
                    Johan Hakkesteegt
                    wrote on last edited by
                    #10

                    I am sorry, I have no experience whatsoever in custom control making... :( However there are plenty of people who have made custom datagrids, and I am sure Google could help you out with this subject. I seem to remember even seeing a few articles right here on the Code Project website with examples, etc. Good luck, Johan

                    My advice is free, and you may get what you paid for.

                    H 1 Reply Last reply
                    0
                    • J Johan Hakkesteegt

                      I am sorry, I have no experience whatsoever in custom control making... :( However there are plenty of people who have made custom datagrids, and I am sure Google could help you out with this subject. I seem to remember even seeing a few articles right here on the Code Project website with examples, etc. Good luck, Johan

                      My advice is free, and you may get what you paid for.

                      H Offline
                      H Offline
                      hsprasain
                      wrote on last edited by
                      #11

                      Hey friend> Thanks, I appreciate your time and efforts. Thank your vey much for your suggestions.

                      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