3
Answers

Select a Specific row in datagrid

Photo of viviansm

viviansm

20y
2.4k
1
Good day. I am a beginner in VB.NET. Please help me in VB.Net coding for the following problems. Q1. I have created 2 forms - a customer form and a search form. When the user click on the Search button in the customer form , the search form will show. The user can search for the customer details either by keying the customer ID(txtCustID) or customer last name(cboCustLastName). The details will show in the datagrid as you can see in the attachment. So far everything is working fine , but how do I write the code if the user double click on the specific row in the datagrid and the details of that selected customer will appear on the customer form so that the user can do the update or delete of that customer in the customer form? Q2. In the customer form, is it possible to do something like this : when the user enter the IC No: 860608-07-5694 which 86 is the year, 06 is month and 08 is day. And this will auto generate The Date of Birth : 08/06/1986. Have a nice day! Thanks and regards, Viv

Answers (3)

1
Photo of Andrzej Wegierski
NA 705 0 20y
It's a syntax for C# - translate into VB I think. Did You use mouse event on DataGrid? Sender should be DataGrid. Check it.
1
Photo of viviansm
NA 21 0 20y
Thank you for you reply. But I still can not solved the problem because of syntax errors (DataGrid)sender. I create a frmCustomer that contains of txtCustID, txtCustFName,txtCustLName,txtCustDob and txtCustIC.... and the Add button, Search button and Exit button. When the user click on the Search button, the frmSearch will show. The user can search for the customer by select the alphabet in a combobox. The details of the customer whose last name start with that alphabet will display in the datagrid. The datagrid in ths frmSearch contains of CustID, CustName, CustDoB. When the user double click on the specific row of the datagrid. It will retrieve the records from the Customer table in SQL server by passing the CustID and display the CustID, CustFName, CustLName, CustDob, CustIC.... to the txtCustID, txtCustFName,txtCustLName,txtCustDob and txtCustIC....on the frmCustmer. Then, the user can do the edit or delete of the record by pressing the button. Please help me in solving the above problem. vivsm I have solved the problems in question 2. thank for your help Thanks and best regards, vi
1
Photo of korie
NA 6 0 20y
Try using something like the following in the mouse_down event of datagrid: (pls excuse syntax errors if any) DataGrid myGrid = (DataGrid)sender; System.Windows.Forms.DataGrid.HitTestInfo hti; hti = myGrid.HitTest(e.X, e.Y); if (hti.Type == System.Windows.Forms.DataGrid.HitTestType.Cell) and (e.Clicks ==2) { //your code, e.g. myRowNo = hti.Row; } For question2, maybe use Substring, e.g. ICNo.Substring(3, 2) will return "06"