اخوانى الاحباب انا ارفقت مثال
ما اريدة هو شرح للمرفق بخصوص الشيك بوكس فقط
لانى تهت فى المثال مش عارف مايخص الشيك بوكس فى الكود
لان المثل بة اكثر من شى ارجو الاهتمام اخوانى المحترفون
جزاكم الله خير نظرا لحاجتى الية
اريد فقط الشيك بوكس ولكم جزيل الشكر
, وايضا وجدت الشرح بالانجليزى للمساعدة فى فهم المرفق ومساعدتى لنفهمة سويا
بما يفيد الكل
وجزاكم الله خيرا
ارجوالمساعده جزاكم الله خيرا
The Checkbox Column
Implementing checkboes for boolean columns involves many of the same constructs as the lookup column, except that we must have one checkbox for every visible row, and we must maintain synchronization between the visible states of the checkboxes and the data that underlies them.
Checkboxes in VB aren't actually boolean, they are tristate; a value property of 1 indicates the check-mark is set, 0 means it is clear, and 2 means it is grayed to symbolize an indeterminate value. Values 1 and 0 map perfectly to SQL Server bit columns but some adjustment is needed for to support [VB-native] variant boolean values, which represent "True" with the numeric value -1. You can use the Abs function to convert a True expression to set a checkbox, e.g.,
checkbox1.value = Abs(str = "Yes")
This will evaluate to 1 if the value of str is "Yes", and 0 otherwise.
To dynamically supply each visible row with a checkbox at runtime, we must create a control array with one element at design time -- at index 0. This can be done in several ways, the easiest of which to explain being: 1.) Create a checkbox on the form; 2.) Set the Index property of that checkbox to 0 (it will be empty by default.)
A non-empty Index property converts a regular control to a control array. Once done, you can create additional elements in that array, using the Load statement in your code. The pair of loops below will adjust the number of array elements up or down to suit the size of the Grid:
Dim
i With
Grid If
(ChkboxArray.UBound <> .VisibleRows) Then
For i = ChkboxArray.UBound + 1 To .VisibleRows - 1
Load ChkboxArray(i)
Next
For i = .VisibleRows To ChkboxArray.UBound
Unload ChkboxArray(i)
Next
End If
End With
Syncing changes made by a user clicking a checkbox is best accomplished using a clone of the recordset that's bound to the Grid -- we don't want to use the same recordset as the Grid uses its record position internally, and altering it causes negative behavior to say the least. A clone is created by calling the Recordset.Clone method (see the ADO documentation for a full discussion of recordset cloning.) Assume for purposes of this handler that a valid clone has been created at class scope or above.
Private Sub cb_Click(index As Integer)
On Error Resume Next
With Grid
rsClone.Bookmark = .RowBookmark(index)
rsClone.Fields(1).Value = cb(index).Value * -1
End With
End Sub
If something other than the grid could change the underlying data while it's displayed in the grid, we must declare the recordset object WithEvents, and process the RecordChangeComplete event. Note the use of a global boolean flag (bInSetCheckboxes) to prevent a recursive event storm.
Private Sub rsClone_RecordChangeComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal cRecords As Long, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
If bInSetCheckboxes = True Then Exit Sub
SetCheckboxes 1, cb
End Sub
That's basically it! The sample application that accompanies this article demonstrates implementation of these technique. (It also includes a utility form called GridSpy, that's explained in a companion article.)
ارجو الاهتمام من يفعل خيرا يجد خيرا