I have a situation where i would want to give user ablity to add new row to the Grid but once the row is added to the grid, the user should only be able to modifiy/update a single column. Rest all the columns should remain read-only or disabled.
I tried almost everything using the AllowUpdate property of the grid and bands and also the CellActivation property for the columns but all in vein.
Please help me the same.
Hi,
I'm not clear on exactly what you want to do. Can the user edit the same column in every row? Or only in new rows?
How are you adding the new rows? Are you using TemplateAddRows or the AddNew buttons?
Hi Mike,
i will give you a brief idea about what really the requirement is.
All the data entry is happening through the grid using the TemplateAddRows and the grid is bound to a datatable of the typed dataset as its datasource . The requirement is that the columns that constitute the unique key in the datatable should not be editable once the row is added to the grid. But at the time of adding the new row all the columns should be editable (including the unique key columns). Any other column (apart from the Unique key columns) should be editable is all the rows, either the existing row in the grid or the new rows.
if my understanding is correct then wingrid follows 2 step process to add a new row to the grid as follows:-
1. Insert a blank new row to the grid.
2. Update the data entered by the user in the newly inserted blank row.
i am not able to identify in which event should i write the code to make the cells or the columns as readonly or else if there is another way to implement this requirement.
It may depend on which AllowAddNewSetting you are using. Whether the TemplateAddRow is fixed or not might affect the order of events. But I tried this out with TemplateOnBottom and this seems to work:
private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { VerifyKeyFieldActivaton(e.Row); } private void ultraGrid1_AfterRowUpdate(object sender, RowEventArgs e) { VerifyKeyFieldActivaton(e.Row); } private static void VerifyKeyFieldActivaton(UltraGridRow row) { if (row.IsTemplateAddRow == false && row.IsAddRow == false) { row.Cells["String 1"].Activation = Activation.Disabled; } else row.Cells["String 1"].Activation = Activation.AllowEdit; }
This solution worked for me, but I might add that if the column is set to NoEdit in the designer, the cell remains NoEdit after this code executes.
Hi Johnie,
I'm not following you. You are saying that you are setting the Activation property on the cell, but it still returns the old value? I don't see how that could possibly happen.
Sorry, but I'm still not clear on what you are saying or what the problem is. I'm also not sure what these screen shots are intended to show.
What, exactly, is the problem? What is "not working?"
Maybe you could post a small sample project demonstrating the issue you are experiencing so I could take a look.
Maybe these screenshots will help:
First the screenshots and then the code. Note that the only thing I change is the CellActivation, no code changes, no other properties change.
This is the solution not working:
http://imageshack.us/a/img541/7508/tworkproduction.png
Here is a screenshot of the designer with the solution not working:
http://imageshack.us/a/img16/2715/tworkdesigner.png
Now, I just change the CellActivation property to "Allow Edit" and it starts working as expected:
http://imageshack.us/a/img855/8186/worksdesigner.png
And in action:
http://imageshack.us/a/img542/8790/worksproduction.png
And, here is the code:
Private Sub companiesGrid_InitializeRow(sender As Object, e As InitializeRowEventArgs) Handles companiesGrid.InitializeRow VerifyKeyFieldActivation(e.Row) End Sub
Private Sub VerifyKeyFieldActivation(row As UltraGridRow) If row.IsTemplateAddRow = False AndAlso row.IsAddRow = False Then row.Cells("CompanyName").Activation = Activation.Disabled Else row.Cells("CompanyName").Activation = Activation.AllowEdit End If End Sub