غير اسم الجدول واسماء الحقول ولا تنس تتاكد من ارقام الاعمده فهنا الكتابه في العمود رقم 0 يعنى الاول والنتيجه في العمود رقم 1 يعنى الثاني
كود :
Dim con As New OleDb.OleDbConnection("Provider=Microsoft........")
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
AddHandler e.Control.TextChanged, AddressOf CellTextChanged
End Sub
Private Sub CellTextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Me.DataGridView1.CurrentCell.ColumnIndex = 0 Then
Using cmd As New OleDb.OleDbCommand("SELECT [name] FROM [table1] WHERE [id] = ?", con)
cmd.Parameters.AddWithValue("@id", Val(CType(sender, DataGridViewTextBoxEditingControl).Text))
If con.State <> ConnectionState.Open Then con.Open()
Me.DataGridView1.Item(1, Me.DataGridView1.CurrentCell.RowIndex).Value = cmd.ExecuteScalar
End Using
End If
End Sub
نفس الكود اللي وضعه الاخ الاستاذ الطالب
هو نفسه اللي في مثال الاخ الاستاذ خضر
الاخ خضر اختصر لك الكود في حدث واحد
والاخ الطلب جعل الكود في حدثين للخلية
واي الكودين طبقت فهي نفس النتيجة
====================
PHP كود :
جمةل اتصالك بقاعدة البيانات Dim con As New OleDb.OleDbConnection("Provider=Microsoft........") اجراء في حدث التحرير مرتبط بحدث تحرير خلية في الجريد فيو Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing AddHandler e.Control.TextChanged, AddressOf CellTextChanged End Sub الاجاراء الاتي في حدث تغيير النص في الخلية وكما رأيت استخدمناه في الاعلى في الجملة [size=small][font=Monaco, Consolas, Courier, monospace] e.Control.TextChanged[/font][/size]
Private Sub CellTextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) الاناذا الخلية اللي انت واقف عليها في خلية في اول عمود اذن نفذ الاجراء الاتي If Me.DataGridView1.CurrentCell.ColumnIndex = 0 Then الاجراء انك تتصل بالجدول مستخدما الجملة Using cmd As New OleDb.OleDbCommand("SELECT [name] FROM [table1] WHERE [id] = ?", con) cmd.Parameters.AddWithValue("@id", Val(CType(sender, DataGridViewTextBoxEditingControl).Text)) اذا الاتصال باقاعدة غير متاح اذا افتح الاتصال بالقاعدة مرر جملة الاستعلام للجدول If con.State <> ConnectionState.Open Then con.Open() الاجراء الاخير يقوم بتعبئة الخلية المقابلة للخلية الاولى في العمود الثاني بعد احضار قيمة جملة الاستعلام السابقة Me.DataGridView1.Item(1, Me.DataGridView1.CurrentCell.RowIndex).Value = cmd.ExecuteScalar End Using
End If End Sub
فين النقطة اللي اشكلت عليك في الكود؟
سبحان الله والحمدللهولا إله إلا الله والله أكبر
اللهم اغْفِرْ لِلمؤمنين والمؤمنات والمسلمين والمسلمات الأحياء منهم والأموات
25-09-15, 03:41 AM (آخر تعديل لهذه المشاركة : 25-09-15, 03:43 AM {2} بواسطة VB.NET.)
اخوي ابوعمر انا ارفقت صورة فيها طريقة الكود الي انا استخدمه ارجو منك الاطلاع
وكيف اعدل عليه
هذا الكود
مع العلم ان حقل الرقم هوا = Doc
وحقل الأسم = Name
Private Sub CellTextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Me.DataGridView1.CurrentCell.ColumnIndex = 0 Then
DA = New SqlClient.SqlDataAdapter("SELECT [Name] FROM [Doctor] WHERE [Doc] = ?", DB)
DA.Fill(DT)
cmd.Parameters.AddWithValue("@id", Val(CType(sender, DataGridViewTextBoxEditingControl).Text))
Me.DataGridView1.Item(1, Me.DataGridView1.CurrentCell.RowIndex).Value = cmd.ExecuteScalar
End Using