Display Autocomplete list based on a Cell Range - c#

I'm trying to do an Excel Add-In and I would like that, in a worksheet that I'm creating, I could select a cell (or a range of cell) that, once you start typing on it (or them), a dropdown-like with possible matches for the typed characters.
Is this possible to do it programmatically?
The closest that I got to achieve this is through the Validation object of the Cell, but a dropdown-like list of options is not displayed just, as you could imagine, I get to display a message indicating that the text is not valid.
As always, thanks in advance!

Related

C# - Find all matches in worksheet using Excel

enter image description here
I would like to find all "NC2" mathces in this worksheet (later the B column values).
I tried with range.find but I got back only one result.
How can I read out these cells? (Which contains NC2)
what I would do is do a data -> filter to get all the cells.
if it helps, conditional formatting would also help to visually find all the cells containing NC2.

Calculating a range of User Inputed values (Unspecified amount) in a textbox created grid

In this assignment I have to create a spreadsheet like excel without importing a library. Now So far I created a grid of 26x26 textboxes (USING CODE), created the indexed rows and alphabet indexed columns. (All of this using a class named Cellfields as a template)
Gave the names (A1,A2,A3 etc) to each cell. and created a formula bar up top.
then I created an if statement that if what the user writes.SubString(0) == to "=" (Meaning the start of a formula),
it will then go to a switch to read the other input the user entered, meaning if user enters =Sum(A1:A3) it will calculate the sum of cells A1,A2,A3.
Now since the calculated cells required are unspecified, I am unable to find a solution to how to calculate a range of values online, as all you can find online are how to import libraries.
I Did try a few things but were immediately removed. I am trying to create a method for it however, have been staring at laptop for the past 3 days.
So you already have a matrix of 26x26 Textboxes, I assume they would be arranged in a Grid, say the name of your Grid is "gridCells".
Now, Users will click on a Cell (actually textbox) and then go to the Formula Bar and type a formula. So On GotFocus of the textboxes, let the textbox remain "Selected", in the sense keep the reference at form level also may be Highlight the Border to show that this is the currently selected cell. This will help you know which Textbox to apply the formula.
Now, when someone types "=Sum(A1:A3)" in the Formula Bar, you would parse the formula, identify it is a "Sum" operation and find out the names of the Textboxes A1, A2 & A3.
From your post looks like you are done this far. Now write a function as below (Not bothering about performance etc. right now).
private String GetValueOfCell(String cellName)
{
foreach (var control in gridCells.Children.OfType<TextBox>())
if (control.Name.Equals(cellName))
return control.Text;
return "";
}
Call this function for all 3 Textboxes, like this:
String value = GetValueOfCell("A1");
And if the value is not empty and can be parsed as int/double, keep doing the Sum and finally store the value in the Text property of our highlighted Textbox.
Hint: You might also want to Save the Formula on the highlighted textbox, because this value goes into the Text property you can use the Tag property to hold the formula.

How to Dselect Usedrange area from spreadsheetgear after using Select Function

I have a Scenario to print UsedRange area From Spreadsheetgear For that i have used below statement
workbookView.ActiveWorksheet.UsedRange.Select();
Using above statement i got like below
and after that Print works Fine. As soon as this goes for print then i want to Dselect that UsedRange.
Means i want like below
How to do this?
You can move the selected cell back to the first cell in the sheet (or any other cell for that matter) after the print code has run using the Activate() method which will deselect the selected cells:
workbookView.ActiveWorksheet.Cells["A1"].Activate();
The API documentation here states To set the active cell, use the IRange.Activate() method.
I don't think it's possible to have no cell selected so it could be worth storing the selected range before you select the entire contents then after the print re-select the previously selected range with the above code.

auto-complete (Intellisense) in Excel sheet created using C#

I have used Microsoft.Office.Interop.Excel namespace to create excel sheets using C#. I want to have the auto-complete or Intellisense feature for a column in it. A particular column should have only two values in it. The values are BUS and TRAIN. When the user types B in any cell of that column; the text in the cell should get changed to BUS and when the user types T, the text should get changed to TRAIN.
I researched and found out there is a method called AutoComplete. But it looks for text from predefined list. How do I specify the predefined list?
any help on this would be greatly appreciated.
Call it as Range.AutoComplete(string), where the Range contains [BUS, TRAIN] or the like.

Excel/Visual Studio/C#. How to change the display name of a cell but keep the formula

I have some code that those:
void mActiveSheet_Change(Microsoft.Office.Interop.Excel.Range Target)
{
if (Target.Cells.Formula.ToString().StartsWith("=FR("))
....
}
So whenever someone uses my custom function "=FR" I can handle it.
That's fine but while the formula value for that cell is fine, the display value is "#NAME?"
I presume that's because Excel does not recognise what =FR is.
Is there a way that I can change the display name but not the formula so I can have something other then "#NAME?" displayed?
I tried Target.Cells.Value2 = "Boo"; but that also changes the formula
I think you got this upside down.
The real goal is not to hide #NAME? error; The goal is to create your own function which can be plugged into Excel as any other standard function, like SQRT() or ABS().
Search Google or MSDN for user defined function Excel C# - there are working examples.
You are correct about #NAME?. That is the Excel error code that is displayed when a function is not recognized. You can't suppress this.
One of the 'dirty tricks' that might work is to hide the message. Detect the background color of the cell, and change the font color to match the background. Unless the cell is highlighted (not just selected) this, in effect, hides the #NAME? error message. After you handle your =FR function and return a result, then you can reset the font color to what it was before so the answer can be seen.

Categories