vorrei il vostro aiuto per un problemino con una stringa ......"Please select"
in una form ho:- 1° combobox: cbLibreria
- 2° combobox: cbDescrizione
- 1° textbox: txtCodeH
- 2° textbox: txtCodeV
ecc
il problema è questo...in avvio su cbLibreria compare "Please select" come da codice.
Una volta selezionata la voce interessata viene abilitata la seconda combobox e "Please select", invece di comparire su cbDescrizione compare su txtCodeH
Allego codice
<<<<<<<<<<<<<<
Private Function GetData(ByVal sql As String) As DataTable
Dim constr As String = "Data Source=Gigi-PC;Initial Catalog=Cad;Integrated Security=true"
Using con As SqlConnection = New SqlConnection(constr)
Using sda As SqlDataAdapter = New SqlDataAdapter(sql, con)
Dim dt As DataTable = New DataTable()
sda.Fill(dt)
Dim row As DataRow = dt.NewRow()
row(0) = 0
row(1) = "Please select"
dt.Rows.InsertAt(row, 0)
Return dt
End Using
End Using
End Function
Private Sub Form6_Load(sender As Object, e As EventArgs) Handles MyBase.Load
cbLibreria.DataSource = Me.GetData("SELECT IdLibreria, Libreria FROM Librerie")
cbLibreria.DisplayMember = "Libreria"
cbLibreria.ValueMember = "IdLibreria"
cbDescrizione.Enabled = False
End Sub
Private Sub cbLibreria_SelectionChangeCommitted(ByVal sender As Object, ByVal e As EventArgs) Handles cbLibreria.SelectionChangeCommitted
cbDescrizione.DataSource = Nothing
cbDescrizione.Enabled = False
If cbLibreria.SelectedValue.ToString() <>"0" Then
Dim sql As String = String.Format("SELECT Code, CodeH, CodeV, Descrizione, LinkH, LinkV FROM Block WHERE Code = {0}", cbLibreria.SelectedValue)
cbDescrizione.DataSource = Me.GetData(sql)
cbDescrizione.DisplayMember = "Descrizione"
cbDescrizione.ValueMember = "Code"
cbDescrizione.Enabled = True
End If
End Sub
Private Sub cbDescrizione_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbDescrizione.SelectedIndexChanged
If (Not Me.cbDescrizione.SelectedItem Is Nothing) Then
Dim SelectedItem = TryCast(cbDescrizione.SelectedItem, DataRowView)
Me.txtCodeH.Text = SelectedItem.Row("CodeH").ToString()
Me.txtCodeV.Text = SelectedItem.Row("CodeV").ToString()
Me.txtLinkOrizzontale.Text = SelectedItem.Row("LinkH").ToString()
Me.txtLinkVerticale.Text = SelectedItem.Row("LinkV").ToString()
Me.lblOr.Text = SelectedItem.Row("CodeH").ToString()
Me.lblVer.Text = SelectedItem.Row("CodeV").ToString()
End If
End Sub
grazie