Merged Cell Data Validation

Hi

I have been experiencing problems trying to attach data validation to merged cells. The code below merges 3 cells and then assigns a simple list of values as a drop-down. All seems fine until the workbook is saved at which point an exception is reported with the message: "An entry with the same key already exists".

For testing purposes the following code can be added to your DataValidation_2005 sample WinForm solution.

----------------------------------------------------------------

sheet.Range["F7:H7"].Merge();
sheet.Range["F7:H7"].CellStyle.Borders.LineStyle = ExcelLineStyle.Medium;
sheet.Range["F7:H7"].CellStyle.Borders[ExcelBordersIndex.DiagonalDown].ShowDiagonalLine = false;
sheet.Range["F7:H7"].CellStyle.Borders[ExcelBordersIndex.DiagonalUp].ShowDiagonalLine = false;

IDataValidation v = sheet.Range["F7:H7"].DataValidation;
v.ListOfValues = new string[] { "A", "B", "C" };
v.PromptBoxText = "Data Validation list";
v.IsPromptBoxVisible = true;
v.ShowPromptBox = true;
v.IsEmptyCellAllowed = false;
v.ErrorBoxTitle = "Invalid Selection";
v.ErrorBoxText = "Please select a value from the drop down list.";
v.ErrorStyle = ExcelErrorStyle.Stop;

----------------------------------------------------------------

Regards

Adrian

3 Replies

LR Lokesh R Syncfusion Team December 17, 2009 04:30 AM UTC

Hi Adrian,


Thank you for your interest on Syncfusion Products.

I have made certain modifications on your code.please try the following code.

_________________________________________________________________
//No need to give the data range again for the validation,because you have already merged the cells //

IDataValidation v = sheet.Range["F7"].DataValidation;

_________________________________________________________________

Let me know if you have any queries.


Regards,

R.lokesh.


AG Adrian Gingell December 17, 2009 08:57 AM UTC

Great, that works! Thanks very much for the quick response.

Adrian


LR Lokesh R Syncfusion Team December 17, 2009 09:08 AM UTC

Hi Adrian,


Thank you for your interest on Syncfusion Products.

You are welcome.

regards,

R.lokesh

Loader.
Up arrow icon