السلام عليكم
يوجد حدث للاداة ComboBox يسمي SelectionChangeCommitted .
السؤال:
ما هو الحدث المناظر له في الاداة DataGridViewComboBoxColumn ؟
السلام عليكم
يوجد حدث للاداة ComboBox يسمي SelectionChangeCommitted .
السؤال:
ما هو الحدث المناظر له في الاداة DataGridViewComboBoxColumn ؟
شكرا
شوف الكود التالي
public class Example
{
/// <summary>
/// Constructor
/// </summary>
public Example()
{
_dataGridView = new DataGridView();
// setup the datagridview here.
// hook up editing control showing event
_dataGridView.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(_dataGridView_EditingControlShowing);
// create a delegate for the method that will handle the event
_comboBoxSelectDelegate = new EventHandler(combo_SelectionChangeCommitted);
}
private DataGridView _dataGridView;
private EventHandler _comboBoxSelectDelegate;
void _dataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
// get the control from the event args.
ComboBox combo = e.Control as ComboBox;
if (combo != null)
{
// remove the event subscription if it exists.
combo.SelectionChangeCommitted -= comboSelectDelegate;
// add a subscription to the event
combo.SelectionChangeCommitted += comboSelectDelegate;
}
}
void combo_SelectionChangeCommitted(object sender, EventArgs e)
{
// handle the event.
ComboBox combo = sender as ComboBox;
if (combo != null)
{
MessageBox.Show(
string.Format("The combobox selected index is: {0}", combo.SelectedIndex)
);
}
}
}و الكود التالي
Private Sub dgv_EditingControlShowing(...) Handles dgv.EditingControlShowing If e.Control.GetType() Is GetType(DataGridViewComboBoxEditingControl) Then Dim cbo As ComboBox = e.Control RemoveHandler cbo.SelectionChangeCommitted, AddressOf cboOnSelectionChangeCommitted AddHandler cbo.SelectionChangeCommitted, AddressOf cboOnSelectionChangeCommitted End If End Sub Private Sub cboOnSelectionChangeCommitted(ByVal sender As Object, ByVal e As EventArgs) Dim cbo As ComboBox = CType(sender, ComboBox) Console.WriteLine(cbo.SelectedValue.ToString()) End Sub
تم تعديل هذه المشاركة بواسطة AhmedElbaz في 21 أكتوبر 2008 في 09:33
متشكر جدا هو فعلا الكود ده --وخصوصا التاني-- هو الكود اللي موجود في منتديات ميكروسوفت وطبعا عشان انا عبقري انجليزي محولتش كتير معه بس لما حضرتك جبته برده قلت لأ لازم استخدم وفعلا اشتغل معايه
بس للاسف
في مشكله وهي اني
بستخدم القيمة اللي تم اختياره ومن الواضح ان الحدث ده مش المناسب عشان كده بطلع الخطأ ده
Object reference not set to an instance of an object.
طيب ايه اللي انا عاوزه بختصر كده، ايه هو الحدث اللي بيحدث لما تتم --تنتهي-- عملية الاختيار عشان زي مقلت هستخدمها بعد كده كالاتي
this.dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[1].Value.ToString()
شكرا مقدما
تم تعديل هذه المشاركة بواسطة الطائر التركي في 21 أكتوبر 2008 في 15:40
شكرا
السلام عليكــم ورحمـة الله وبركاتــة
خلاص الحمد وصلت للي انا عاوز
بس ظهر خطاء اخر وهو
ظهور هذه الرسالة عند الاختيار اكتر من مرة وبصرحة مش فاهم طبيعة الخطاء يعني بيظهر بتحديد امتي مش عارف
وعلي فكرة وانا ببحث عن الموضوع كان ظهر امامي مقال في احد المدونات وبتكلم عن المشكلة بس للاسف كان بلغة الانجليزيه
اتمني اجد الحل
تم تعديل هذه المشاركة بواسطة الطائر التركي في 24 أكتوبر 2008 في 23:17
شكرا