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.
Unfortunately, activation email could not send to your email. Please try again.

Merged Cell Data Validation

Thread ID:

Created:

Updated:

Platform:

Replies:

92062 Dec 16,2009 04:25 PM Dec 17,2009 04:08 AM Windows Forms 3
loading
Tags: XlsIO
Adrian Gingell
Asked On December 16, 2009 04:25 PM

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

Lokesh R [Syncfusion]
Replied On December 16, 2009 11:30 PM

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.

Adrian Gingell
Replied On December 17, 2009 03:57 AM

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

Adrian

Lokesh R [Syncfusion]
Replied On December 17, 2009 04:08 AM

Hi Adrian,


Thank you for your interest on Syncfusion Products.

You are welcome.

regards,

R.lokesh

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;