Powershell Text Field Auto-Complete - textbox

I have a text box for which I want to use autocomplete, reading from a text file source. I'm following the general example on MSDN here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.autocompletemode(v=vs.110).aspx
My code doesn't throw an error (haha), but it's not populating the text box when I start a string, either.
$LogList = Get-Content(Resolve-Path "file\logs.txt")
$comp_or_filepath.AutoCompleteSource.CustomSource
$comp_or_filepath.AutoCompleteCustomSource.AddRange($LogList)
$comp_or_filepath.AutoCompleteMode.SuggestAppend
Is there a good example for this I can see online? I found one for a combo box, but I don't think it applies in my case.
Thank you!

Here what I hope you're looking for nearly 7 years on?
I'm looking into AutoCompleteCustomSource for PowerShell and very little info can be got on it.
You were trying to access a prop that didn't exist.
$comp_or_filepath.AutoCompleteSource.CustomSource
$comp_or_filepath.AutoCompleteMode.SuggestAppend
That should have been:
$comp_or_filepath.AutoCompleteSource = 'CustomSource'
$comp_or_filepath.AutoCompleteMode = 'SuggestAppend'
Here's the code with comments:
Add-Type -AssemblyName System.Windows.Forms
#Form setup
$Form = New-Object System.Windows.Forms.Form
$Form.StartPosition = 'CenterScreen'
#Set up the control comp_or_filepath
$comp_or_filepath = New-Object System.Windows.Forms.ComboBox
$comp_or_filepath.Width = 280
$comp_or_filepath.AutoCompleteSource = 'CustomSource'
$comp_or_filepath.AutoCompleteMode = 'SuggestAppend'
$cbArr = #('Mixed', 'More stuff', 'ANOTHER THING cONTENT', 'Item ?', 'Mixed item')
$comp_or_filepath.Items.AddRange($cbArr)
# Setup the autocomplete source by reading the file contents and adding each line.
$autoCompleteUsrSrc = New-Object System.Windows.Forms.AutoCompleteStringCollection
Get-Content(Resolve-Path "file\logs.txt") | ForEach-Object {
$autoCompleteUsrSrc.AddRange($_)
}
$comp_or_filepath.AutoCompleteCustomSource = $autoCompleteUsrSrc
# Add controls and start form.
$Form.Controls.Add($comp_or_filepath)
[void]$Form.ShowDialog()

Related

PhpSpreadSheet how to have a new line?

Good day everyone i want to achieve a new line in my spreadsheet cause i had two to three values here
This code over here has a protection so the viewers cannot edit easily in excell they must have password on the admin to be enable to edit.
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$spreadsheet->getActiveSheet()->getProtection()->setSheet(true);
$spreadsheet->getActiveSheet()->getProtection()->setSort(true);
$spreadsheet->getActiveSheet()->getProtection()->setInsertRows(true);
$spreadsheet->getActiveSheet()->getProtection()->setFormatCells(true);
$spreadsheet->getActiveSheet()->getProtection()->setPassword('test');
$spreadsheet->getActiveSheet()->getStyle('D')->getAlignment()->setWrapText(true);
$spreadsheet->getDefaultStyle()
->getFont()
->setName('Times New Roman')
->setSize(14);
$sheet->setCellValue('A1', 'Control Number');
$sheet->setCellValue('B1', 'Requesting Unit');
$sheet->setCellValue('C1', 'Project Details');
$sheet->setCellValue('D1', 'Attached Transaction Form');
This line of code uses to fetch the data in the database in this scenario my attached form has two to three values so thats why i want to create a break or a new line.
$data = $this->m->getlog1();
$slno = 1;
$start = 2;
foreach($data as $d){
$sheet->setCellValue('A'.$start, $d->control_number);
$sheet->setCellValue('B'.$start, $d->requesting_unit);
$sheet->setCellValue('C'.$start, $d->project_details);
$sheet->setCellValue('D'.$start, $d->attached_form);
$start = $start+1;
$slno = $slno+1;
}
You have to use line breakes in the text and
$spreadsheet->getActiveSheet()->getStyle('A1')->getAlignment()->setWrapText(true);
For more Information see documentation.
According to this commit this commit this will be automatically included in future releases.
Maybe you must/will use some auto fit then take a look to this code.

Ignore the "Select Sheet" message on Excel Interop

Maybe someone here can help me out with this. I am trying to convert all XLS to XLSX/M files with powershell and interop. So far so good. In my next step, I have to adapt the link sources in each file, which works sometimes (also from XLS to XLSX/M).
I don’t know why, but sometimes the original worksheet name does not exist in the linked Excel file and results in a pop up with which the user has to interact:
I actually really don’t care so much about the sheet and I just want to ignore the message so that the script can continue.
In my code I use the function ChangeLink, like this:
$workbook.ChangeLink($fileLink_old, $fileLink_new)
I also have deactivated any warning on the excel object itself, but nothing helps:
$excel.DisplayAlerts = $False
$excel.WarnOnFunctionNameConflict = $False
$excel.AskToUpdateLinks = $False
$excel.DisplayAlerts = $False
The most convinient way for me would be just ignoring the pop up.
Is there a way without going through all cells by itself or modifing the externalLinks/_rels inside of the excel file?
Thanks in advance
Stephan
Edit:
To loop through each cell, not really efficient
ForEach ($Worksheet in #($workbook.Sheets)) {
Write-Host $Worksheet.Name
ForEach ($filelink in $fileLinks){
$worksheetname = $null
$fl_we = $fileLink.Substring(0, $fileLink.LastIndexOf('.'))
$found = $Worksheet.Cells.Find($fl_we.Substring(0, $fl_we.LastIndexOf('\')) + '\[' + $fl_we.Substring($fl_we.LastIndexOf('\')+1))
if($found -ne $null){
Write-Host Search $filelink
Write-Host $Worksheet.Cells($found.Row,$found.Column).Formula
$str_formula = $Worksheet.Cells($found.Row,$found.Column).Formula
$worksheetname = $str_formula.Substring($str_formula.IndexOf(']')+1,$str_formula.IndexOf('!')-$str_formula.IndexOf(']')-2)
Write-Host $worksheetname -ForegroundColor DarkGray
#Add worksheets with filename to list
}
}
}
#Check if worksheet exists in linked file

Scan automation with PowerShell and WIA - How to set PNG as image type

What I have: I'm using PowerShell 2.0 and WIA to quickly scan and save an image from my flatbed scanner. The goal was to avoid all dialogs, just a single click. This code is simple, short and works.
$deviceManager = new-object -ComObject WIA.DeviceManager
$device = $deviceManager.DeviceInfos.Item(1).Connect()
foreach ($item in $device.Items) {
$image = $item.Transfer()
}
$image.SaveFile("D:\Scan.$($image.fileExtension)")
Problem: The method above always produces BMP files. But I wanted PNG files instead.
I saw this C# code which uses another WIA method where the user was able to pass some arguments to the scan dialog like PNG as file format
Now I wonder if and how it's possible to achieve the same only with PowerShell
I found most of the code here
http://deletethis.net/dave/?uri=http%3A%2F%2Fcerealnumber.livejournal.com%2F47638.html
http://ardalis.com/powershell-control-over-nikon-d3000-camera
http://msdn.microsoft.com/en-us/library/windows/desktop/ms630806(v=vs.85).aspx
PS: Just in case your solution involves the 'Take Picture' command (wiaCommandTakePicture). Unfortunalty my CanoScan LIDE 210 doesn't support that command
You should pass the FormatID string argument to the Transfer method. The list of available formats is available in MSDN
However, there's a catch. As explained here, the Transfer method doesn't have to observe the requested format, and the output must be converted manually in that case. By converting the MSDN's VB example to PowerShell we get this (works on my machine with my scanner):
$deviceManager = new-object -ComObject WIA.DeviceManager
$device = $deviceManager.DeviceInfos.Item(1).Connect()
$wiaFormatPNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
foreach ($item in $device.Items) {
$image = $item.Transfer($wiaFormatPNG)
}
if($image.FormatID -ne $wiaFormatPNG)
{
$imageProcess = new-object -ComObject WIA.ImageProcess
$imageProcess.Filters.Add($imageProcess.FilterInfos.Item("Convert").FilterID)
$imageProcess.Filters.Item(1).Properties.Item("FormatID").Value = $wiaFormatPNG
$image = $imageProcess.Apply($image)
}
$image.SaveFile("C:/my_full_path/test.png")

How to edit an attribute using Xtext?

I want to use Xtext's editor to edit a String attribute of an EObject instead of editing a text file. How can I achieve this? I found this thread but it only mentions the workaround of creating a temp file. There must be a more elegant solution. I thought of creating a custom EditorInput but I'm not sure where to start. Thanks in advance for any pointers!
Since 2.2, the supported solution is using IEditedResourceProvider with an EmbeddedEditorFactory (since editing an attribute belongs to an embedded editor anyway). Sample code in Xtend (the attribute is updated whenever the editor changes):
val injector = MyDslActivator.instance.getInjector(MyDslActivator.COM_EXAMPLE_MY_DSL)
val resourceSet = injector.getInstance(IResourceSetProvider).get(null)
val fileExtension = injector.getInstance(Key.get(String, Names.named(Constants.FILE_EXTENSIONS)))
val resourceProvider = [|
resourceSet.createResource(createURI('''temp.«fileExtension»''')) as XtextResource
]
injector.getInstance(EmbeddedEditorFactory).newEditor(resourceProvider).withParent(parent) => [
createPartialEditor("", editedAttribute ?: "", "", false)
document.addModelListener[_ | editedAttribute = document.get]
]
Based on: EditTemplateDialog source, StackOverflow, Eclipse Forum.

Call javascript in sharepoint custom field

I am creating a custom field in SharePoint 2007. I have seen other solutions where the current site URL was default value of a text field.
How can I get this current site URL?
I have got one answer whiches states that I shall use JavaScript, but where do I put the script?
I hope you can help.
BR
To answer 1
I am new to SharePoint and am not quiet sure where to put the java script. Normaly i just give the initial value to the field in the FieldEditor.cs file but how can I do this with the javascript?
Here follows a picute of my files.
I have tried to put it into FiledEditor.cs but this results in the value of myString is written in the top of the web page.
Here is my current code:
string myScript = "var currentUrl = document.URL; LabelLookupFieldTargetURLText.Text = currentUrl;";
Page.ClientScript.RegisterClientScriptBlock(LabelLookupFieldTargetURLText.GetType(), "LabelLookupFieldTargetURLTextJavaScript", myScript);
I found the answer my self. I don't need to use a java script. I can just use SPContext.Current.Site.Url
use javascript:
var nowUrl = document.URL;
yourTextfiled.value = nowUrl;
you can read this:http://www.w3schools.com/jsref/dom_obj_document.asp

Resources