I have a datagrid which displays information from a database. I not able to figure out how to bind the column values to a textbox when the row is selected. I would appreciate any ideas on how to accomplish this. function GenerateForm { ######################################################################## # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.8.0 # ######################################################################## #Custom Variables $computer = gc env:computername #End Custom Variables #Custom Functions #region Database query, generated code # Database connection $DBConnection = New-Object System.Data.OleDb.OledbConnection $RecordSet = New-Object System.Data.OleDb.OleDbDataAdapter $Cmd = New-Object System.Data.OleDb.OleDbCommand $dt = New-Object System.Data.dataTable $CommandBuilder = New-Object System.Data.OleDb.OleDbCommandBuilder $DBConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\todd\Documents\SAPIEN\Scripts\Stores1.mdb;Persist Security Info=False" $DBConnection.Open() #EndRegion Custom Functions #region Import the Assemblies [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null [reflection.assembly]::loadwithpartialname("System.Data") | out-null #endregion #region Generated Form Objects $bindingSource1 = new-object System.Windows.Forms.BindingSource $form1 = New-Object System.Windows.Forms.Form $cbo_Type = New-Object System.Windows.Forms.ComboBox $lbl_Type = New-Object System.Windows.Forms.Label $btn_Select = New-Object System.Windows.Forms.Button $lbl_instructions = New-Object System.Windows.Forms.Label $timezoneBox = New-Object System.Windows.Forms.TextBox $txtTimeZone = New-Object System.Windows.Forms.Label $btnCXL = New-Object System.Windows.Forms.Button $btnExecute = New-Object System.Windows.Forms.Button $newComputerNameBox = New-Object System.Windows.Forms.TextBox $txtNewComputerName = New-Object System.Windows.Forms.Label $computerNameBox = New-Object System.Windows.Forms.TextBox $txtComputerName = New-Object System.Windows.Forms.Label $datadisplay = New-Object System.Windows.Forms.DataGrid $dataGridTableStyle2 = New-Object System.Windows.Forms.DataGridTableStyle $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState #endregion Generated Form Objects #---------------------------------------------- #Generated Event Script Blocks #---------------------------------------------- #Provide Custom Code for events specified in PrimalForms. function Open-dt() { $datadisplay.DataSource = $bindingSource1 $Cmd.Connection = $DBConnection $Cmd.CommandText = "Select number, shortname, address, city, state, phone, timezone from TBL_Stores" $RecordSet.SelectCommand = $Cmd $CommandBuilder.DataAdapter = $RecordSet $RecordSet.Fill($dt) } function Print-dt() { $bindingSource1.DataSource = $dt } $btnExecute_OnClick= { #TODO: Place custom script here function renameAndReboot([string]$computer, [string]$newname) { $comp = gwmi win32_computersystem -computer $computer $os = gwmi win32_operatingsystem -computer $computer $comp.Rename($newname) $os.Reboot() } } ##Combo Button Click $cbo_Type_OnClick= { #TODO: Place custom script here } ##Combo Button Click End $handler_label1_Click= { #TODO: Place custom script here } $handler_label2_Click= { #TODO: Place custom script here } $handler_txtTimeZone_Click= { #TODO: Place custom script here } $Form1_Load= { } $btn_Select_OnClick= { } ##Button CXL $btnCXL_OnClick= { #TODO: Place custom script here $form1.Close() } ##Button CXL End $handler_dataGrid1_Navigate= { #TODO: Place custom script here } ##Select Button $btn_Select_OnClick= { #TODO: Place custom script here } ##Select Button End $OnLoadForm_UpdateGrid= { Open-dt Print-dt } $OnLoadForm_StateCorrection= {#Correct the initial state of the form to prevent the .Net maximized form issue $form1.WindowState = $InitialFormWindowState } #---------------------------------------------------- #region Generated Form Code $form1.Text = "WMForm" $form1.Name = "form1" $form1.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 710 $System_Drawing_Size.Height = 515 $form1.ClientSize = $System_Drawing_Size $cbo_Type.FormattingEnabled = $True $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 187 $System_Drawing_Size.Height = 21 $cbo_Type.Size = $System_Drawing_Size $cbo_Type.DataBindings.DefaultDataSourceUpdateMode = 0 $cbo_Type.Name = "cbo_Type" $cbo_Type.Items.Add("Digital Signage")|Out-Null $cbo_Type.Items.Add("POS")|Out-Null $cbo_Type.Items.Add("Primary")|Out-Null $cbo_Type.Items.Add("WorkStation")|Out-Null $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 160 $System_Drawing_Point.Y = 261 $cbo_Type.Location = $System_Drawing_Point $cbo_Type.Sorted = $True $cbo_Type.TabIndex = 12 $form1.Controls.Add($cbo_Type) $lbl_Type.TabIndex = 11 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 126 $System_Drawing_Size.Height = 23 $lbl_Type.Size = $System_Drawing_Size $lbl_Type.Text = "Select Computer Type:" $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 13 $System_Drawing_Point.Y = 264 $lbl_Type.Location = $System_Drawing_Point $lbl_Type.DataBindings.DefaultDataSourceUpdateMode = 0 $lbl_Type.Name = "lbl_Type" $lbl_Type.add_Click($handler_label2_Click) $form1.Controls.Add($lbl_Type) $btn_Select.TabIndex = 10 $btn_Select.Name = "btn_Select" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 75 $System_Drawing_Size.Height = 23 $btn_Select.Size = $System_Drawing_Size $btn_Select.UseVisualStyleBackColor = $True $btn_Select.Text = "Select" $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 475 $System_Drawing_Point.Y = 199 $btn_Select.Location = $System_Drawing_Point $btn_Select.DataBindings.DefaultDataSourceUpdateMode = 0 $btn_Select.add_Click($btn_Select_OnClick) $form1.Controls.Add($btn_Select) $lbl_instructions.TabIndex = 9 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 441 $System_Drawing_Size.Height = 23 $lbl_instructions.Size = $System_Drawing_Size $lbl_instructions.Text = "Highlight the row which matches your store and then press the Select Button >>" $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 12 $System_Drawing_Point.Y = 204 $lbl_instructions.Location = $System_Drawing_Point $lbl_instructions.DataBindings.DefaultDataSourceUpdateMode = 0 $lbl_instructions.Name = "lbl_instructions" $lbl_instructions.add_Click($handler_label1_Click) $form1.Controls.Add($lbl_instructions) $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 100 $System_Drawing_Size.Height = 20 $timezoneBox.Size = $System_Drawing_Size $timezoneBox.DataBindings.DefaultDataSourceUpdateMode = 0 $timezoneBox.Text = "" $timezoneBox.Name = "timezoneBox" $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 475 $System_Drawing_Point.Y = 234 $timezoneBox.Location = $System_Drawing_Point $timezoneBox.TabIndex = 8 $form1.Controls.Add($timezoneBox) $txtTimeZone.TabIndex = 7 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 123 $System_Drawing_Size.Height = 23 $txtTimeZone.Size = $System_Drawing_Size $txtTimeZone.Text = "Current Time Zone:" $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 353 $System_Drawing_Point.Y = 237 $txtTimeZone.Location = $System_Drawing_Point $txtTimeZone.DataBindings.DefaultDataSourceUpdateMode = 0 $timezoneBox.Text = $timezone $txtTimeZone.Name = "txtTimeZone" $txtTimeZone.add_Click($handler_txtTimeZone_Click) $form1.Controls.Add($txtTimeZone) $btnCXL.TabIndex = 6 $btnCXL.Name = "btnCXL" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 75 $System_Drawing_Size.Height = 23 $btnCXL.Size = $System_Drawing_Size $btnCXL.UseVisualStyleBackColor = $True $btnCXL.Text = "Cancel" $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 106 $System_Drawing_Point.Y = 480 $btnCXL.Location = $System_Drawing_Point $btnCXL.DataBindings.DefaultDataSourceUpdateMode = 0 $btnCXL.add_Click($btnCXL_OnClick) $form1.Controls.Add($btnCXL) $btnExecute.TabIndex = 5 $btnExecute.Name = "btnExecute" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 75 $System_Drawing_Size.Height = 23 $btnExecute.Size = $System_Drawing_Size $btnExecute.UseVisualStyleBackColor = $True $btnExecute.Text = "Execute" $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 25 $System_Drawing_Point.Y = 480 $btnExecute.Location = $System_Drawing_Point $btnExecute.DataBindings.DefaultDataSourceUpdateMode = 0 $btnExecute.add_Click($btnExecute_OnClick) $form1.Controls.Add($btnExecute) $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 187 $System_Drawing_Size.Height = 20 $newComputerNameBox.Size = $System_Drawing_Size $newComputerNameBox.DataBindings.DefaultDataSourceUpdateMode = 0 $newComputerNameBox.ReadOnly = $True $newComputerNameBox.Text = $newName $newComputerNameBox.Name = "newComputerNameBox" $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 160 $System_Drawing_Point.Y = 289 $newComputerNameBox.Location = $System_Drawing_Point $newComputerNameBox.TabIndex = 4 $form1.Controls.Add($newComputerNameBox) $txtNewComputerName.TabIndex = 3 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 126 $System_Drawing_Size.Height = 23 $txtNewComputerName.Size = $System_Drawing_Size $txtNewComputerName.Text = "New Computer Name:" $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 13 $System_Drawing_Point.Y = 289 $txtNewComputerName.Location = $System_Drawing_Point $txtNewComputerName.DataBindings.DefaultDataSourceUpdateMode = 0 $txtNewComputerName.Name = "txtNewComputerName" $form1.Controls.Add($txtNewComputerName) $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 188 $System_Drawing_Size.Height = 20 $computerNameBox.Size = $System_Drawing_Size $computerNameBox.DataBindings.DefaultDataSourceUpdateMode = 0 $computerNameBox.Text = "$computer" $computerNameBox.Name = "computerNameBox" $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 159 $System_Drawing_Point.Y = 235 $computerNameBox.Location = $System_Drawing_Point $computerNameBox.TabIndex = 2 $form1.Controls.Add($computerNameBox) $txtComputerName.TabIndex = 1 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 150 $System_Drawing_Size.Height = 23 $txtComputerName.Size = $System_Drawing_Size $txtComputerName.Text = "Current Computer Name:" $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 13 $System_Drawing_Point.Y = 238 $txtComputerName.Location = $System_Drawing_Point $txtComputerName.DataBindings.DefaultDataSourceUpdateMode = 0 $txtComputerName.Name = "txtComputerName" $form1.Controls.Add($txtComputerName) $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 686 $System_Drawing_Size.Height = 185 $datadisplay.Size = $System_Drawing_Size $datadisplay.DataBindings.DefaultDataSourceUpdateMode = 0 $datadisplay.HeaderForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0) $datadisplay.Name = "datadisplay" $datadisplay.TableStyles.Add($dataGridTableStyle2)|Out-Null $datadisplay.DataMember = "" $datadisplay.TabIndex = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 12 $System_Drawing_Point.Y = 12 $datadisplay.Location = $System_Drawing_Point $datadisplay.add_Click($dataRow_OnClick) #$datadisplay.add_Navigate($handler_dataGrid1_Navigate) $form1.Controls.Add($datadisplay) $dataGridTableStyle2.HeaderForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0) $dataGridTableStyle2.DataGrid = $datadisplay #endregion Generated Form Code $form1.add_Load($OnLoadForm_UpdateGrid) #Save the initial state of the form $InitialFormWindowState = $form1.WindowState #Init the OnLoad event to correct the initial state of the form $form1.add_Load($OnLoadForm_StateCorrection) #Show the Form $form1.ShowDialog()| Out-Null } #End Function #Call the Function GenerateForm