Getting randomly selected cells in a table - c#

I'm working on a word ribbon MS Office application in VS2010 using C#.
When I have a table in the document, I want to add some text in randomly selected cells of the table when a button on the ribbon is pressed..
The problem is, everytime I select random number of cells the WrdApp.ActiveWindow.Selection.Cells gets only the last selected cell.
Here's the code :
foreach (Cell myCell in WrdApp.ActiveWindow.Selection.Cells)
{
myCell.Range.Text = "text" + myCell.Range.Text
}

Related

With C#/dot.NET, auto-validating new cell value on DataGridView when checking a cell

I'm working on a project coded in C#/.NET.
I have a main form that open a new form when a click on a button.
In this new form, I have a DataGridView filled with a DataTable :
dataGridView_color_selection.DataSource = GLOBALS.ListDataTableColorSets[comboBox_color_sets.SelectedIndex];
My first column is a checkBox column.
When I check or uncheck a row, I want this to be updated in DataTable.
But after checked a row, I have to select another row to validate the previous change.
I want the DataTable upgraded each time I check or uncheck a cell in real time
I've tried to change some properties on DataGridView control but it doesn't have work.
I've tried to catch the event Click on DataGridView and directly upgrade DataTable with value of CheckBox cell. No result.

focus in a cell value of DataGridView C# windows forms on adding a row

I have a DataGridView . When I click on a button a row gets added into the DataGridView. There are 3 columns named 'Rate','Qty' and 'Total'. On adding a row, by default full row is selected. How can I focus on a 'Qty' column by default so that I need not move mouse there to edit the cell value?
You can use following this:
DataGridView1.CurrentCell = DataGridView1.Rows[rowindex].Cells[columnindex]
or
DataGridView1.CurrentCell = DataGridView1.Item("ColumnName", 1)
and you can directly focus on Editing by:
dataGridView1.BeginEdit(true)

How to read excel dynamically data and get combobox values

I have to dynamically read about 2000 files in Excel xlsx format, to import data to database using csharp. It´s not tabular data, no head columns at all, the data has to be read dynamically, because the positions of the cells change according to the product data, we have labels cells to find the data. My biggest problem is I can not read the value of combo boxes cause positions, name and quantity of cells/combos will change depending the product, but the labels will remain the same. I tried to export to every single format type but it doesn´t works, the combo selected value after specific cell label dissapears.
Any possible solution?
Ex. of my spreadsheet:
row A1: label|value|null value|label|value|merge cells label|value
row A2: label|producttypecombovalue
row A3: label|producttypecombovalue
row A4: label|producttypecombovalue...
row AX..: label|value|label|value|merge cells label|value
If the combo boxes are all positioned over the cell to the right of the label then you can filter all of the combos on the sheet by looking at their location (ie. their TopLeftCell property, or Top and Left properties) and using the one which most closely matches the expected position of the one you're looking for.
In VBA (using Forms combos, which from your screenshot are what you're dealing with) -
Sub tester()
Dim o
For Each o In ActiveSheet.OLEObjects
Debug.Print o.Name, o.Top, o.Left, o.TopLeftCell.Address(), _
TypeName(o.Object)
Next o
End Sub

How to customize the header in my report?

Q :
I want to make the header in my report like this but I don't know how to do this in right way.
They are three columns with a general header (GPA) and special header for each one which its value comes from a parameter.
In the Report Designer:
You will need two heading rows, so (if you don't already have them) right-click on the existing heading row and select Insert Row.
Enter 'GPA' into the top heading row cell above the first of your three parameter-based columns, and your three parameter-based headings into the appropriate cells on the second header row.
Click on the GPA cell, then hold down Shift and click on the next two cells so that the three top row heading cells above the parameter-based columns are all selected. Right-click on the selected cells and select Merge Cells.
With the merged cells still selected, set alignment, bolding and background colour as required.

Need to access selected data from a excel addin (Visual C#)

Im trying to build a addin that can take some a selection of cells from a excel sheet and then put them together in the first cell i have celected. Between the cells there will be a user selected seperator.
example:
I select the 3 cells A1-A3 with the values A B and C
I then bring up my addin and chose the seperator to be ", ".
The addin should then place a the String "A, B, C" in the cell A1.
But I cant figure out how to access the data I have selected in the excel sheet.
var range = (Range)Globals.ThisAddIn.Application.ActiveWindow.Selection;

Categories

Resources