none
How to display the Member of combo box by selecting value

    Question

  • Hi,

    I have vb2005, I made one grid and if you click on a row header(I have used it if any other good to replace it plz let me know) it will be available to modify below the grid in text and combo boxes till text box it works fine but with combo box some time it dispalys member some time not, how can I assign value to combo box so it will be available always as displayed member(becomes the selection) to user , I am assinging value like this.

    With dgvLetters

     If e.RowIndex >= 0 Then

    txtLetterID.Text = CType(.Rows(e.RowIndex).Cells(0).Value, Integer)

    cbxDept.SelectedValue = .Rows(e.RowIndex).Cells(4).Value.ToString

    cmbxStatus.Selecteditem = .Rows(e.RowIndex).Cells(9).Value.ToString

    cbxUserID.SelectedValue = .Rows(e.RowIndex).Cells(10).Value.ToString

    txtRemarks.Text = .Rows(e.RowIndex).Cells(12).Value.ToString

    End If

    end with

    Thanks and regards

    Tuesday, March 06, 2007 10:16 AM

Answers

  • Simple solution repeat the code in cell(4) as the cbxdept value.    If you are generating a value for that column then use that code to fill the combobox.   

    But over all you may want to take a look at datasets and bindings.  You can create a calculation column in the dataset and bind the dataset to the datagridview.  Then create controls also bond to the dataset.  When a new row is selected the other bond controls will change to the current data row.

     

    Friday, March 09, 2007 3:32 AM

All replies

  • Try something like this:

    cbxDept.SelectedIndex = cbxDept.FindString(.Rows(e.RowIndex).Cells(4).Value.ToString)

    Tony

    Tuesday, March 06, 2007 2:01 PM
  • Hi Tony,

    Thanks for reply, problem with your provided solution is that in (.Rows(e.RowIndex).Cells(4).Value.ToString) I have code rather than Display member and according to my knowledge .findstring searches for the provided string in Display member not value member of a combo box(If I am wrong plz, correct me), is there any way so it can do search in value member.

    Thanks and Regards, Khawar.

    Wednesday, March 07, 2007 4:30 AM
  • Simple solution repeat the code in cell(4) as the cbxdept value.    If you are generating a value for that column then use that code to fill the combobox.   

    But over all you may want to take a look at datasets and bindings.  You can create a calculation column in the dataset and bind the dataset to the datagridview.  Then create controls also bond to the dataset.  When a new row is selected the other bond controls will change to the current data row.

     

    Friday, March 09, 2007 3:32 AM