Click here to Skip to main content
15,917,731 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Disable the controls in a form... Pin
Jay Royall20-Jun-08 5:28
Jay Royall20-Jun-08 5:28 
QuestionTransparent Form and windows media player Pin
divyesh143220-Jun-08 1:24
divyesh143220-Jun-08 1:24 
AnswerRe: Transparent Form and windows media player Pin
nogChoco22-Jun-08 5:35
nogChoco22-Jun-08 5:35 
QuestionDataGridView to Xml Pin
Anoop Brijmohun19-Jun-08 23:39
Anoop Brijmohun19-Jun-08 23:39 
AnswerRe: DataGridView to Xml Pin
Ajay.k_Singh20-Jun-08 3:19
Ajay.k_Singh20-Jun-08 3:19 
GeneralRe: DataGridView to Xml Pin
Anoop Brijmohun20-Jun-08 3:27
Anoop Brijmohun20-Jun-08 3:27 
QuestionSubClassing Word2007 Fluent Ribbon... Pin
S2Coder19-Jun-08 23:18
S2Coder19-Jun-08 23:18 
QuestionAdding data in a combo box from the database Pin
Aigini19-Jun-08 21:27
Aigini19-Jun-08 21:27 
I have a few questions regarding the code below.

In the first highlighted section of the code below the employee names are added into the combo box using a large string array.



    ' Declare comboBox1 as a ComboBox.    

         Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox

    ' This method initializes the combo box, adding a large string 
    ' array but limiting the drop-down size to six rows so the combo box
    ' doesn't cover other controls when it expands. 
   

Private Sub InitializeComboBox()
        Me.ComboBox1 = New System.Windows.Forms.ComboBox

        Dim employees() As String = New String() {"Hamilton, David", _
            "Hensien, Kari", "Hammond, Maria", "Harris, Keith", _
            "Henshaw, Jeff D.", "Hanson, Mark", "Harnpadoungsataya, Sariya", _
            "Harrington, Mark", "Harris, Keith", "Hartwig, Doris", _
            "Harui, Roger", "Hassall, Mark", "Hasselberg, Jonas", _
            "Harnpadoungsataya, Sariya", "Henshaw, Jeff D.", "Henshaw, Jeff D.", _
            "Hensien, Kari", "Harris, Keith", "Henshaw, Jeff D.", _
            "Hensien, Kari", "Hasselberg, Jonas", "Harrington, Mark", _
            "Hedlund, Magnus", "Hay, Jeff", "Heidepriem, Brandon D."}

        ComboBox1.Items.AddRange(employees)                

        Me.ComboBox1.Location = New System.Drawing.Point(136, 32)
        Me.ComboBox1.MaxDropDownItems = 5
        Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDown
        Me.ComboBox1.Name = "ComboBox1"
        Me.ComboBox1.Size = New System.Drawing.Size(136, 81)
        Me.ComboBox1.TabIndex = 0
        Me.Controls.Add(Me.ComboBox1)
    End Sub



    ' This method is called when the user changes his or her selection.
    ' It searches for all occurrences of the selected employee's
    ' name in the Items array and adds the employee's name and 
    ' the number of occurrences to TextBox1.Text.

    ' CAUTION   This code exposes a known bug: If the index passed to the 
    ' FindStringExact(searchString, index) method is the last index 
    ' of the array, the code throws an exception.




    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

        Dim comboBox As comboBox = CType(sender, comboBox)

        ' Save the selected employee's name, because we will remove
        ' the employee's name from the list.        

        Dim selectedEmployee = CType(ComboBox1.SelectedItem, String)

        Dim count As Integer = 0
        Dim resultIndex As Integer = -1

        ' Call the FindStringExact method to find the first 
        ' occurrence in the list.                

        resultIndex = ComboBox1.FindStringExact (ComboBox1.SelectedItem)

        ' Remove the name as it is found, and increment the found count. 
        ' Then call the FindStringExact method again, passing in the index of the
        ' current found item so the search starts there instead of 
        ' at the beginning of the list.                

       While (resultIndex <> -1)
            ComboBox1.Items.RemoveAt(resultIndex)
            count += 1
            resultIndex = ComboBox1.FindStringExact _
            (selectedEmployee, resultIndex)
        End While

        ' Update the text in Textbox1.        

             TextBox1.Text = TextBox1.Text & Microsoft.VisualBasic.vbCrLf _
             & selectedEmployee & ": " & count    

End Sub



1)How do I do the same for datas that are in the database(SQL Server 2000) instead? Do I have to use the below line of code? Or if not, what do I have to do to insert the data into the combo box?

Me.Inv_itemcategoryTableAdapter.Fill(Me.dsInventory.inv_itemcategory)

Inv_itemcategory is the name of the table adapter holding the data. dsInventory is the name of the data source.

2) In the second highlighted section (updating the textbox), can I use the same method to update another combo box and also a text box instead of only updating a text box?
AnswerRe: Adding data in a combo box from the database Pin
Christian Graus19-Jun-08 21:43
protectorChristian Graus19-Jun-08 21:43 
Questioncalling exe Pin
kadkir19-Jun-08 20:20
kadkir19-Jun-08 20:20 
AnswerRe: calling exe Pin
Christian Graus19-Jun-08 20:47
protectorChristian Graus19-Jun-08 20:47 
GeneralRe: calling exe Pin
kadkir19-Jun-08 21:55
kadkir19-Jun-08 21:55 
GeneralRe: calling exe Pin
Dave Kreskowiak20-Jun-08 13:15
mveDave Kreskowiak20-Jun-08 13:15 
GeneralRe: calling exe Pin
kadkir20-Jun-08 17:42
kadkir20-Jun-08 17:42 
GeneralRe: calling exe Pin
LloydA11121-Jun-08 15:24
LloydA11121-Jun-08 15:24 
QuestionVB 6.0 & CR9 "Load Report Failed" error 50003 Pin
zomby80200319-Jun-08 19:52
zomby80200319-Jun-08 19:52 
QuestionVB 6.0 & CR9 "Load Report Failed" error 50003 Pin
zomby80200319-Jun-08 19:51
zomby80200319-Jun-08 19:51 
Questionvb6 string truncated Pin
AJ du Plessis19-Jun-08 19:18
AJ du Plessis19-Jun-08 19:18 
AnswerRe: vb6 string truncated Pin
Christian Graus19-Jun-08 20:10
protectorChristian Graus19-Jun-08 20:10 
GeneralRe: vb6 string truncated Pin
AJ du Plessis19-Jun-08 20:25
AJ du Plessis19-Jun-08 20:25 
QuestionPassing value within form and function VB.NET 2003 Pin
drexler_kk19-Jun-08 16:14
drexler_kk19-Jun-08 16:14 
AnswerRe: Passing value within form and function VB.NET 2003 Pin
Christian Graus19-Jun-08 18:41
protectorChristian Graus19-Jun-08 18:41 
QuestionRe: Passing value within form and function VB.NET 2003 Pin
drexler_kk19-Jun-08 19:31
drexler_kk19-Jun-08 19:31 
Questionhow can i print my form axacly like itself Pin
Nika Asgari19-Jun-08 11:47
Nika Asgari19-Jun-08 11:47 
AnswerRe: how can i print my form axacly like itself Pin
Christian Graus19-Jun-08 12:13
protectorChristian Graus19-Jun-08 12:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.