简体   繁体   中英

Excel: How to lock a cell based on another cell in the same row

I am working on export excel sheet using Devexpress library- Spreadsheet in c#.

I have 2 columns, 1st column with a dropdown (True/False) and 2nd column is just a text field. If row has 1st column selected as True then it should lock the 2nd column and not allow to enter any values in it.

Was trying this ( https://docs.devexpress.com/WPF/DevExpress.Xpf.Spreadsheet.SpreadsheetControl.CellValueChanged ) event to catch and do my logic but didn't had any luck.

Need help..

You can use CellBeginEdit event

void spreadsheetControl1_CellBeginEdit(object sender, SpreadsheetCellCancelEventArgs e) {
    if (e.ColumnIndex == 1) {
        var cellValue = e.Worksheet[e.RowIndex, 0].Value;
        e.Cancel = cellValue.IsBoolean && cellValue.BooleanValue;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM