Hey guys,

I am having a problem with my program; I am trying to get my program to allow a user to be able to insert data into a specific cell in my data grid view, but it seems to be unable to do it accurately.

Below is the code that I am using for the button which adds the data to the data grid. It collects data from combo boxes and time pickers on the form and is then supposed to use it to determine which cell to insert the data into as well as formulate the data that is supposed to be inserted.

It is able to correctly formulate the data to be inserted, however it doesn't select the right cell.

Code:
Dim x = AssignStaffMemberCB.SelectedIndex
Dim y = AssignDayCB.SelectedIndex
Dim z = AssignTimeDTP.Value
Dim u = AssignEndTimeDTP.Value

Timetable_DataGrid.Rows(x).Cells(y).Value = z & (" - ") & u
I think the problem is that it is selecting the index of the selected item in each of the combo boxes with regards to it's position in the combo box itself and is using that to determine the position of where the data should be inserted, which isn't what I want it to do because it is inserting the data into the wrong cells.

I want the program to be able to use the actual string itself that the user has selected instead of it's index to determine where the formulated data should go in the data grid by comparison, however I am not sure on how to program this.

I have tried to change the variables to what I have below but that just gives me an error because it isn't valid:


Code:
Dim x = AssignStaffMemberCB.SelectedItem
Dim y = AssignDayCB.SelectedItem
Dim z = AssignTimeDTP.Value
Dim u = AssignEndTimeDTP.Value

Timetable_DataGrid.Rows(x).Cells(y).Value = z & (" - ") & u
Just for clarification the staff member combo box is simply storing the first names of staff members and the assign day combo box is storing the days of the week, nothing else.

I would really appreciate it if you guys could help me out with this

Thanks and have a good day.