Making a particular cell of datagrids uneditable [modified]
-
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
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
-
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
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, JohanMy advice is free, and you may get what you paid for.
-
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
-
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, JohanMy advice is free, and you may get what you paid for.
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
-
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
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.
-
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.
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. -
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.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.
-
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.
-
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?
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.
-
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.