Devexpress C# XtraGrid Single Cell Edit Issues
I'm about to pull my hair out for something that is probably very simple.
This is using the XtraGrid.
Let's assume I have two columns and x number of rows, contained in one column is just a checkbox that I set with the columnedit property and the other is a value. I have a text box set to be the editor of this second value.
How can I set this up so that if I check the checkbox for that row, it will allow editing to the number in the value field next to it? I have the allowedit set to true for the checkbox column, but if I set the allowedit to true for the 2nd column in say the checkbox checkedchanged event handler, it will allow all of the cells in that column to be edited. I have no other properties like readonly set or anything like that.
How can I distinguish between a single cell in that column and activate the editor while leaving the others readonly 开发者_Python百科based on that checkbox in the same row? I have a feeling it involves using ShowingEditor and CustomRowCellEdit, but I'm not sure how to set that up.
Could someone take me through what I would need to do in order to accomplish this? What settings do I need to put for the readonly/allowedit properties for this column and what would I need to put in those ShowingEditor/CustomRowCellEdit methods to do this? I'm really new at this so it is probably a really basic question, but I need some help! Some code examples for C# to determine which cell is selected would help me, but I just need to figure this out. Thanks!!!
Yes your are right, you have to manage this by implementing the ShowingEditor
Event
This code for demonstration porpuses:
First I bond the gridview1
to a RandomClass
public class RandomClass
{
public bool AllowEdit { get; set; }
public string Text { get; set; }
public randomClass()
{
this.AllowEdit = true;
Text = "Text1";
}
}
then implement the ShowingEditor
Event, Every time the gridview1
tries to open the editor for the second column
it checks whether AllowEdit
column checked or not and take action according to it
private void gridView1_ShowingEditor(object sender, CancelEventArgs e)
{
if (gridView1.FocusedColumn.FieldName == "Text"
&& !IsAllowingEdit(gridView1, gridView1.FocusedRowHandle))
{
e.Cancel = true;
}
}
private bool IsAllowingEdit(DevExpress.XtraGrid.Views.Grid.GridView view,int row)
{
try
{
bool val = Convert.ToBoolean(view.GetRowCellValue(row, "AllowEdit"));
return val;
}
catch
{
return false;
}
}
精彩评论