Thank all you for last replies

here i hve a problem in my project .
I have 2 form . In frm1 i have a datagridview which contain all information of student i.e ID, NAME , CLASS No. , ADDRESS , Department and course .
In this form i hve 2 button New and Edit.

The 2nd form is Edit form which contain ID(txtbox), NAME(txtbox) , CLASS No.(txtbox) , ADDRESS(txtbox) , Department(combobox) and course(combobox) .
Departmen and course combobox pickup data from database.

Now
when the user click the edit button Edit_form will open and it fill all field. I try a code below it fill all feild but not select the correct combobox index i.e i select a row with deptment computer when i click the edit button the editform open , it automaticly select the computer in department combobox.

Code

dim frmedit as new form_Edit
Dim i As
Integer
i =
DataGridView1.
CurrentRow.Index
frm.textbox1.Text
= DataGridView1.
Item(0, i).Value
frm.TextBox2.
Text =
DataGridView1.
Item(1, i).Value
frmedit.TextBox3.
Text =
DataGridView1.
Item(2, i).Value

frmedit.CmbDEP.
Text =
DataGridView1.
Item(3, i).Value

it show the 'computer' department in combobox. But not selecting the 'computer' index.
I need how i retrive the correct index of computer

plz help

try something like this,

combobox.selectedValue= form1.gridview1.item(1,2).value.toString

Do some update Khair if it was solved.

Thank alots.
The code you provided not fullfill my requirment.

i fill the department combObox with the follwing code and it load during opening the Edit Form

dim str as String = " select dep_id,dep_name from Department "
dim da as new sqldataAdapter(str, MyCN)
DIM DS as new Dataset
da.fill(ds,"Department")
cmbDep.datasource= ds
cmbDep.datasource = ds.tables("Department")
cmbDep.displaymember = "dep_name"
cmbDep.ValueMember = "dep_id"
cmbDep.selectedIndex= -1

the department Combobox contain i.e Computer , Maths, English.

Now
When i select a row in Datagridview with department 'Computer' and click on Edit the Edit form load and select the 'Computer' in Department combnbox with its Index i.e if 'computer' on second index it select the index 2 .
My problem arise during Updation . It update the record with 0 instead of computer Index 2.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.