We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

gridboundcolumn.style.readonly=true does''t work

Hi, Ihave written a code to make grid columns read only. as soon as i laod the form,I read the name of GridBoundColumns and try to make them readonly. i use the following code private void ApplySecurity(GridBOundColumn c, bool readonlyAccess) { c.style.readonly = readonlyAccess; } On some grid above code doesn''t work. what could be the reason? Could it be the sequence when i call this method, i mean before i assign the ''datasource'' or after? what are the factor that may cause this code to now to work? Please help. Thanks,

26 Replies

AD Administrator Syncfusion Team November 20, 2005 10:10 AM UTC

The order may matter depending upon whether the grid has ever been visible as a child of a container control. One thing you can try is calling grid.Binder.InitializeColumns after you have set this style. If that does not work, also add a call to grid.Refresh after the InitializeColumns call. If you can upload a sample showing the problem, we can de bug it here.


AD Administrator Syncfusion Team November 21, 2005 08:16 PM UTC

I tried both didn’t help, moreover in my method I don’t have the grid control so this could be another issue where I have to get the grid control. Now could it be because at design time I have assigned DataBoundColumns to the grid be able to define read-only columns using reflection? I don’t define any mapping at for these columns at design time. At Run time I assigned a collection of business objects to the grid. Could this be the cause of problem? Please do help! Thanks,


AD Administrator Syncfusion Team November 21, 2005 08:29 PM UTC

If you can upload a sample we can try to debug it here. You should put stops in your code where you set the readonly property. There, after setting it, check to make sure it got set. Then put stops immediately before and after where you set the DataSource. In the stops, check the ReadOnly property to see if it is still set. If the ReadOnly property is set initially, but not set later, you should be able to track down the code that is resetting it, and hopefully avoid it somehow. The likely places to check are before and after setting the DataSource, and then before and after the grid is displayed.


AD Administrator Syncfusion Team November 21, 2005 09:26 PM UTC

It is really not possible for me to upload the sample. I tried the following code in a button clicked. private void button3_Click(object sender, System.EventArgs e) { this.GridBoundColumn1.ReadOnly =true; this. GridBoundColumn1.StyleInfo.ReadOnly =true; this.grid.Binder.InitializeColumns(); this.grid.Refresh(); int i=0; i=10; } I have the stop at each line of the code. The ‘dBoundColumn1.ReadOnly’ and ‘GridBoundColumn1.StyleInfo.ReadOnly’ both were set to true at every line. Still my column is not read-only. I have assigned the dataset before clicking on the button. Does this give you any clue?


AD Administrator Syncfusion Team November 21, 2005 09:35 PM UTC

Some more info: I am using the following code in to make a column read-only this.GridBoundColumn1.StyleInfo.ReadOnly =true; And I found out that this property is always ‘TRUE’ even before and after assigning the datasource. But it doesn’t draw itself as Read-Only. But the following property is always FLASE this.GridBoundColumn1.Readonly I tried the refresh() but didn’t get any help.


AD Administrator Syncfusion Team November 21, 2005 09:52 PM UTC

I have another grid on the same Form and my read-only code is working like charm. The only thing that is different is that the Grid which working is a ‘Flat’ GDBG and the other one which is not working is a hierarchical view of the GDBG. Is there a different way to make a column read-only in case of hierarchical view? Because a very simple one line code in button clicked doesn’t make a column read only. Does this give you any clue? This is really big issue in my application, this is related to security. Please help me.


AD Administrator Syncfusion Team November 21, 2005 09:59 PM UTC

The gridboundcolumn for a child table has to be gotten from the proper hierarchylevel for that table. Are you using the code discussed in this thread to get at the proper child level? http://www.syncfusion.com/Support/forums/message.aspx?MessageID=37302


AD Administrator Syncfusion Team November 21, 2005 10:16 PM UTC

I just used the following code and found out that level.GridBoundColumns is always empty doesn’t matter which level # I use. GridHierarchyLevel level = this.gdbgDepartmentBudget.Binder.GetHierarchyLevel(1); GridBoundColumnsCollection gbcc = (level.GridBoundColumns == null || level.GridBoundColumns.Count == 0) ? level.InternalColumns : level.GridBoundColumns; gbcc[1].StyleInfo.ReadOnly = true; gbcc[2].StyleInfo.ReadOnly = true; gbcc[3].StyleInfo.ReadOnly = true; Let me give you some info about requirement. I have stored the GirdDataBOund columns and their associated access (read-only or not) in database. In Form load I read the Column name and it’s access from database and try to set the column access accordingly. It works fine for flat grid but for hierarchical columns I am having problem. How would you do this? I always have GridDataBound columns in my grid and I store their name in database.


AD Administrator Syncfusion Team November 21, 2005 11:01 PM UTC

Here is a sample showing a readonly column in a child table. http://www.syncfusion.com/Support/user/uploads/GDBG_NestereadOnly_97ee3eb2.zip


AD Administrator Syncfusion Team November 22, 2005 02:06 AM UTC

Your sample doesn''t use the GridDataBound columns. In my case my starting point is a control that is basically GridDataBound column in a hierarchical view. Now I need to make that column readonly. Would it be possible for your sample to define GridDataBound columns and then on button click make a column read-only using GridDataBound column. Please do help me.


AD Administrator Syncfusion Team November 22, 2005 04:51 AM UTC

Clay, I have modified the sample to use the GridDataBound column. i also added a button to makre a column readonly. now this is not working. I need to make all the cells in gbcParentName column read-only. Please make thi ssample working, if possible. thanks,

GDBG_NestereadOnly_new.zip


AD Administrator Syncfusion Team November 22, 2005 09:15 AM UTC

In this sample, when I click the button, the parentname column becomes readonly for me. I cannot type into it. Initially, the data does not appear in any of the columns in the parent grid because you have not set the MappingNames on the gridboundcolumns so the grid knows which colum is which. So, to get the data to show up, I added these 3 lines right above the line that sets the datasource. this.gbcParentId.MappingName = "parentID"; this.gbcParentName.MappingName = "ParentName"; this.gbcParentDec.MappingName = "ParentDec"; this.gridDataBoundGrid1.DataSource = ds; Once I did this, the parent grid comes up ok for me, and when I click the button, the column becomes red and I cannot type into it. (You can see the edit cursor when you click it), but you cannot type into the cell. I am using version 3.3.


AD Administrator Syncfusion Team November 22, 2005 05:15 PM UTC

Hi, I am using 3.0.1.1 May be it''s version issue, but did you expand all the rows? it doesn''t make the child and grandchild cells read-only. only parent cells are read-only. if this is working for you the way i want, could you please upload the code please? otherwise, is there a way to solve this? Thanks,


AD Administrator Syncfusion Team November 22, 2005 05:36 PM UTC

Here it is. ALl I did was to add those 3 lines. http://www.syncfusion.com/Support/user/uploads/GDBG_NestereadOnly_e69e2cbf.zip


AD Administrator Syncfusion Team November 22, 2005 07:41 PM UTC

I have attached a screen shot of running sample and probably you can see the only parent cells are read(Read-only). Is it a version issue? Thanks,

screen0.zip


AD Administrator Syncfusion Team November 22, 2005 07:47 PM UTC

I do not know what the issue is. If you will upload a sample project showing the problem, I can try to find out. Here is something else you can try. Add a grid.Model.QueryCellInfo event handler. In the handler, set e.Style.ReadOnly = true. Does this make the cells readonly?


AD Administrator Syncfusion Team November 22, 2005 07:54 PM UTC

I have attached the same sample, which basically doesn''t work for me. i am using 3.0.1.1, could you please try in that version. I have to run that code out side the grid events. so ther is no pint of setting anything in grid events. Thanks,

GDBG_NestereadOnly.zip


AD Administrator Syncfusion Team November 22, 2005 08:13 PM UTC

In the sample you attached, I uncommented the 2 lines that you had commented out. gbcc[1].StyleInfo.ReadOnly = true; gbcc[1].StyleInfo.BackColor = Color.Red; With those lines in, the child table column is red and readonly for me both using version 3.3 and 3.0.1.0. I do not have version 3.0.1.1 available to me now. It woul dbetomorrow before I can try that version.


AD Administrator Syncfusion Team November 22, 2005 09:46 PM UTC

I commented out these two lines on purpose. As I told you that I have to use gridboundcolumn column, the code that make a column red only has access to gridboundcolumn control, it doesn’t have access to grid control itself. So I have to use the following syntax gridBoundColumn.readonly = true; or gridBoundColumn.styleinfo.readonly = true; I understand I am not the only one out here who need help, but this is something that will cause a big change for our application. The following is the actual code from my class. private void PerformSecurity(GridBoundColumn control,string controlSecurity) { Boolean Readonly = false; control.StyleInfo.TextColor = System.Drawing.Color.Black; if (controlSecurity == "R" || controlSecurity == "N") { Readonly = true; if (controlSecurity == "N") { control.StyleInfo.TextColor = control.StyleInfo.BackColor; } } //control.ReadOnly = true; control.StyleInfo.ReadOnly = Readonly; } Thanks,


AD Administrator Syncfusion Team November 22, 2005 11:02 PM UTC

In that code, gbcc[1] is just a GridBoundColumn. You can use your code to set the readonly property on it. It does happen to be the GridBoundColumn that determines the format of a particular child column. How are you defining the GridBoundColumn on which you are setting the StyleInfo.ReadOnly property? Is it THE gridboundcolumn for the hierarchylevel and column that you want to make readonly? If not, the you must do something to associate this GridBoundColumn with the proper column in the proper child table. It sounds like you want to define an arbitrary GridBoundColumn not associated with anything. Say with code like: GridBoundColumn gbc = new GridBoundColumn(); gbc.StyleInfo.ReadOnly = true; gbc.StyleInfo.BackColor = Color.Red; So, now you have an arbitrary GridBoundColumn. At some point, you have to associate this GridBoundColumn with a grid. When you are ready to associate it with the grid, you must use the MappingName and you must use the hierarchylevel. At that point, you could have code like: GridHierarchyLevel level = this.gridDataBoundGrid1.Binder.GetHierarchyLevel(1); GridBoundColumnsCollection gbcc = (level.GridBoundColumns == null || level.GridBoundColumns.Count == 0) ? level.InternalColumns : level.GridBoundColumns; level.InternalColumns["Name"].StyleInfo = gbc.StyleInfo; //gbc is your cached GridBoundColumn But you will have to do both these tasks. Just defining a GridBoundColumn and setting properties in it is only part of what you need to do. Are you doing both tasks in your code?


AD Administrator Syncfusion Team November 23, 2005 05:20 PM UTC

My grid bound column is not a arbitrary column. It is associated with a hosting form & Grid. I use the following code to get an instance of GRIDBOUNDCOLUM on the current hosting form. controlName = ‘name of the control on the form , could be a button or a GridBoundColumn name’ AppForm = ‘Instance of host form, which has the Grid and GridBoundColumn’ //Get the type of control Type t = ( AppForm.GetType().InvokeMember( controlName, BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.GetField , null, AppForm, null ) as object).GetType(); //Grid controls (columns) needed be handled differently if (t.Name == "GridBoundColumn") { GridBoundColumn control = AppForm.GetType().InvokeMember( controlName, BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.GetFiel d , null, AppForm, null ) as GridBoundColumn; PerformSecurity(control,controlSecurity); } else { Control control = AppForm.GetType().InvokeMember( controlName, BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.GetFiel d , null, AppForm, null ) as Control; SetupControl(control,controlSecurity); Visited.Add(control); } private void PerformSecurity(GridBoundColumn control,string controlSecurity) { Boolean Readonly = false; control.StyleInfo.TextColor = System.Drawing.Color.Black; if (controlSecurity == "R" || controlSecurity == "N") { Readonly = true; if (controlSecurity == "N") { control.StyleInfo.TextColor = control.StyleInfo.BackColor; } } //control.ReadOnly = true; control.StyleInfo.ReadOnly = Readonly; } Since now you have bigger picture now. Could you please go thru the code and suggest something. Thanks,


AD Administrator Syncfusion Team November 23, 2005 05:30 PM UTC

Please list the code on your hosting form that: 1) Creates the GridBoundColumn object 2) Assigns it to the particular child hierarchy level of the instanciated grid. And if you put stops in your code, do the two pieces of code you list here get hit prior to the code that you listed in your previous post?


AD Administrator Syncfusion Team November 23, 2005 06:02 PM UTC

I have included a snapshot of for a GridBoundColumn in my hosting form in sequence of their actual execution. I also included the code of security component. My datastore ‘dsSecurityData’ has the name of controls (like “gbcComapny”) . # “Assigns it to the particular child hierarchy level of the instanciated grid. “—I don’t do that probably this is why it is why I am having program. My code is working for flat grid, it is not working for hierarchical view. Does this give you any information? Thanks,

sample8.zip


AD Administrator Syncfusion Team November 23, 2005 06:26 PM UTC

You have to set the GridBoundColumn to the child hierarchy. Other wise, the grid does not know where to use your gridbound column. Suppose you grid had 15 nested child tables, each with 5 columns each in them (all with the same column names). Suppose you create a collection 5 x 15 or 75 GridBoundColumns. How is the grid going to determine which column goes with with childtable and column? This is why you need to set the particular GridBoundColumn into the the particular hierarchy level. Your reflection code works in this sample. http://www.syncfusion.com/Support/user/uploads/GDBG_NestereadOnly_cba3c393.zip In this sample, care was taken to pass in the GridBoundColumn that was being used by the particular hierarchy. Here is another sample where a GridBoundColumn was just created, and your code used to set properties on it, and then later this GridBoundColumn object was applied to the child hierarchy. (The sameple just changes out teh styleinfo. If you want to actually use teh exact same obejct, then you would have to build a new GridBoundColumnCollection and just setting teh styleinfo is simpler.) http://www.syncfusion.com/Support/user/uploads/GDBG_NestereadOnly_9b701b46.zip I suspect you want to try to do something like this latter sample. After your reflection that sets the properties, then you must tell the grid what gridboundcolumns go with what levels. You need to do this if you are just creating the GridBoundColumns without using the grid. But if you let the grid create them, an dyou pass these GridBoundColumns to your reflection code, then you do not have to do this second step of associating the GridBoundColumns with the hierarchy levels. This is what the first sample does.


AD Administrator Syncfusion Team November 23, 2005 09:56 PM UTC

Thanks clay, I have the following concerns #1 In second sample I see you are using gbcc["Name"].StyleInfo = gbc.StyleInfo; “Name” which is basically a mapping name? Can I use something like gbcc["gbc"].StyleInfo = gbc.StyleInfo; M.Imp. #2 If you have notice in my security code where i am creating a GridBoundColumn using reflection, I don''t have the GridControl itself but I do have the Host form. Is there a way I can find out the GridControl to which this GridBoundColumns belogs to, so that I can use the following code Step#1 GridBoundColumn gbc = Create GridBoundColumns using Reflection Step#2 SetProperties("gbc"); Step#3 gridDataBoundGrid1 = Find Grid Control somehow on the hostform to which this column belongs to Step#4 GridHierarchyLevel level = gridDataBoundGrid1.Binder.GetHierarchyLevel(1); GridBoundColumnsCollection gbcc = (level.GridBoundColumns == null || level.GridBoundColumns.Count == 0) ? level.InternalColumns : level.GridBoundColumns; gbcc = (level.GridBoundColumns == null || level.GridBoundColumns.Count == 0) ? level.InternalColumns : level.GridBoundColumns; Step#5 gbcc["gbc"].StyleInfo = gbc.StyleInfo; Thanks,


AD Administrator Syncfusion Team November 23, 2005 10:52 PM UTC

1) You must use the DataColumn.ColumnName as the indexer as that is how the grid will know what column this GridBoundColumn is mapped to. 2) If you arbitarily create a GridBoundColumn, there is no association to any grid. It it only when you set the MappingName property and add it to the GridBoundColumns collection does some grid (and possibly some hierarchylevel) become the owner of the GridBoundColumn. And, even at that point, there is not way for the GridBoundColumn object to know what grid (and maybe hierarchylevel) owns it. If you need this information, you can derive the GridBoundColumn and add a owner property that you could set as you add the GridBoundColumn to the grid.

Loader.
Live Chat Icon For mobile
Up arrow icon