Click here to Skip to main content
15,881,735 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
If e.ColumnIndex = 0 Then      'Delete button clicked
               'delete button clicked inside PositionDataGridView
               If sender Is interviewDataGridView Then
                   'Messagebox notifying the user they're about to delete a record
                   dlgResult = MessageBox.Show("Delete This INTERVIEW record " & interviewDataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex + 1).Value.ToString _
                                       & "?", "Do you want To delete this record", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation,
                                       MessageBoxDefaultButton.Button2)
                   'only delete if the user clicks 'OK'
                   If dlgResult = System.Windows.Forms.DialogResult.OK Then
                       'delete current row
                       PositionCompanyBindingSource.RemoveCurrent()
                   End If
               End If
           End If
       ElseIf sender Is interviewdatagridview AndAlso e.ColumnIndex <> 0 Then
           If Not PositionCompanyBindingSource.Current Is Nothing Then
               drPC = (PositionCompanyBindingSource.Current).row
               drCom = drPC.GetParentRow("FK_PositionCompany_Company")
               drPos = drPC.GetParentRow("FK_PositionCompany_Position")
           Else drPC = Nothing
           End If
           If drPC Is Nothing Then
               PosTextBox.Text = ""
               ComTextBox.Text = ""
           Else
               PosTextBox.Text = drPos.Title.ToString
               ComTextBox.Text = drCom.Name.ToString
           End If
       End If
Posted
Comments
CHill60 30-Nov-15 19:39pm    
So what is actually wrong with your code? In what way does it not do what you expect?
Member 12176796 30-Nov-15 20:46pm    
I'm getting nothing in my textboxes. The datarow.getparentrow and datarow.getchildrows are confusing me

1 solution

Why not use the BindingSource you already have, PositionCompanyBindingSource, and connect it to your text boxes?

VB
ComTextBox.DataBindings.Add(New Binding("Text", PositionCompanyBindingSource, "Name"))

(Not sure if this binding source is the correct one)

You can also use a DataSet, let's call it ds1
VB
ComTextBox.DataBindings.Add(New Binding("Text", ds1, "Company.Name"))

or a DataTable
VB
DataTable dt1 = ds1.Tables("Company")
ComTextBox.DataBindings.Add(New Binding("Text", dt1, "Name"))


See Control.DataBindings Property[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900