double click on datagrid and fill in related fields on main form form
-
Hello, I have a datagrid on one form and I would like to fill in my main form when I double click on any record in the datagrid. How can I do that? I am using VB.NET. thanks, Joseph
programmer
hi, So simple:-D, jst refer all controls name by using relative formname. e.g. if your main form's name is "MainForm" & the form having datagrid where you r going to take records, its name is "RecordForm". then refer datagrid by that form's name e.g. RecordForm.datagrid suppose u hav to fill one value from datagrid's 1st col & 1st row in textbox present on MainForm then write-> textbox1.text= RecordForm.datagrid.item(1,1).value.
priya
-
hi, So simple:-D, jst refer all controls name by using relative formname. e.g. if your main form's name is "MainForm" & the form having datagrid where you r going to take records, its name is "RecordForm". then refer datagrid by that form's name e.g. RecordForm.datagrid suppose u hav to fill one value from datagrid's 1st col & 1st row in textbox present on MainForm then write-> textbox1.text= RecordForm.datagrid.item(1,1).value.
priya
-
Do I need to do anything regarding double clicking any record on the datagrid? thanks, Joseph
programmer
You write the code in procedure Private Sub MyDatagrid1_RowHeaderMouseDoubleClick(...) ''write code of filling mainform Here ''u can refer to select items of datagrid by Mainform1.textbox1=MyDatagrid1.item(0,e.rowindex).value Mainform1.textbox2=MyDatagrid1.item(1,e.rowindex).value ..... . . ''Like this fill all items of mainform end sub As user clicks on rowheader of datagrid's specific cell ur code will be generated if again any doubt , do ask. I wnt to ask that , Is all of controls on mainform are textboxes?
priya
-
hi, So simple:-D, jst refer all controls name by using relative formname. e.g. if your main form's name is "MainForm" & the form having datagrid where you r going to take records, its name is "RecordForm". then refer datagrid by that form's name e.g. RecordForm.datagrid suppose u hav to fill one value from datagrid's 1st col & 1st row in textbox present on MainForm then write-> textbox1.text= RecordForm.datagrid.item(1,1).value.
priya
Hi, thank you for your help. It is going good. I am almost done with my application except the one that I am asking. yes. all the fields are textboxes on the main form. I am getting this error when I click on the one of the datagrid cells. Unable to cast object of type 'System.String' to type 'System.Windows.Forms.TextBox'. here is my code: Private Sub FSSCallerRecordsDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles FSSCallerRecordsDataGridView.CellContentClick Form3.HospitalNumberTextBox = FSSCallerRecordsDataGridView.Item(5, e.RowIndex).Value P.S. Form3 is the main form. And the reason I wrote Item(5) is that Hospital number on the datagrid is column number 5. (is it correct) *****Is it necessary I can email you the project? thanks, joseph
programmer
-
Hi, thank you for your help. It is going good. I am almost done with my application except the one that I am asking. yes. all the fields are textboxes on the main form. I am getting this error when I click on the one of the datagrid cells. Unable to cast object of type 'System.String' to type 'System.Windows.Forms.TextBox'. here is my code: Private Sub FSSCallerRecordsDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles FSSCallerRecordsDataGridView.CellContentClick Form3.HospitalNumberTextBox = FSSCallerRecordsDataGridView.Item(5, e.RowIndex).Value P.S. Form3 is the main form. And the reason I wrote Item(5) is that Hospital number on the datagrid is column number 5. (is it correct) *****Is it necessary I can email you the project? thanks, joseph
programmer