تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] مساعدة تعديل على الكود
#1
السلام عليكم
لمدا هدا الكود لا يشتغل
 Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

       Try

           fillCombo("SELECT * FROM msarahin", ComboBox1)
           ComboBox1.DisplayMember = "msarahin"
           ComboBox1.ValueMember = "MSARH_NAM"
       

           TextBox16.Text = ComboBox1.SelectedText.ToString()




       Catch ex As Exception
           MsgBox(ex.Message)

       End Try

   End Sub



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

        Try

            TextBox16.Text = ComboBox1.SelectedText.ToString()

        Catch ex As Exception

        End Try




    End Sub
الرد }}}
تم الشكر بواسطة:
#2
لأن فيه أخطاء !
الرد }}}
تم الشكر بواسطة:
#3
1 - من الواضح انها دالة لتعبئة الكومبوبوكس لكن الدالة الرئيسية fillCombo غير موجودة
2- الخصائص DisplayMember و ValueMember من المفروض والافضل ان يتم تحديدها من خلال الدالة السابقة

من الممكن ان تفيدك هذه الدالة كن يجب ان تكون لديك معرفة ولو بسيطة بالبرمجة

كود :
Public Sub fillCombo( sqlQuery As String,comboBox As ComboBox, displayMember As String, valueMember As String)
   If comboBox Is Nothing Then
       Throw New ArgumentNullException(NameOf(comboBox))
   End If

   Dim dataTable As New System.Data.DataTable()
   comboBox.Items.Clear()
   comboBox.Text = ""
   comboBox.DataSource = Nothing

   Try
           Using connection As OleDbConnection = GetConnection() ' نفترض أنها تعيد OleDbConnection
            If connection.State <> ConnectionState.Open Then
                connection.Open() ' فتح الاتصال
            End If

            Using cmd As OleDbCommand = connection.CreateCommand()
                cmd.CommandText = sqlQuery
                Using adapter As New OleDbDataAdapter(cmd)
                    adapter.Fill(dataTable)
                End Using
            End Using
        End Using

        comboBox.DataSource = dataTable
        comboBox.DisplayMember = displayMember
        comboBox.ValueMember = valueMember


       If comboBox.Items.Count > 0 Then
           comboBox.SelectedIndex = 0
       End If
   Catch ex As Exception
       MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
   End Try
End Sub

استدعاء الدالة يكون بالشكل التالي

كود :
fillCombo("SELECT * FROM msarahin", ComboBox1 ,"msarahin" ,"MSARH_NAM")
الرد }}}
تم الشكر بواسطة: asmarsou



التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم