PDA

View Full Version : سوال: غیر فعال کردن آیتمهای list box



JustAcMilan
شنبه 31 فروردین 1392, 23:39 عصر
با سلام خدمت اساتید
چجوری میشه بعضی آیتمهای لیست باکس رو غیر فعال کرد
من یه لیست باکس دارم میخواستم همه آیتمهاش غیر فعال باشه بجز آیتمهای اول، ششم، یازدهم، شانزدهم و...

لطفا کمک کنید

vaheeed
یک شنبه 01 اردیبهشت 1392, 08:42 صبح
تا حالا چنین چیزی ندیدم امیدوارم دوستان دیگه کمکتون کنن ولی اگه میخواستم همچین کاری کنم ایتم های اضافه رو کلا حذف میکردم و وقتی لازم بود دوباره اضافه میکردم

JustAcMilan
یک شنبه 01 اردیبهشت 1392, 12:46 عصر
vaheeed:
من می خوام نشون داده بشه اما غیر فعال باشه






یه نمونه کد vb.net هم پیدا کردم اگه کسی میتونه به c# تبدیلش کنه ممنون میشم

Public Class Form1
Dim DL As New List(Of Integer) 'Disabled List
Public Property DisabledList() As List(Of Integer)
Get
Return DL
End Get
Set(ByVal value As List(Of Integer))
DL = value
End Set
End Property
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ListBox1.DrawMode = DrawMode.OwnerDrawFixed
DisabledList.Add(2)
DisabledList.Add(1)
End Sub
Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
e.DrawBackground()
Dim myBrush As Brush
Dim myBackColor As Color = Color.White
Dim myForeColor As Color = Color.Black
Dim myFont As Font = Me.Font
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
myBackColor = Color.Blue
myForeColor = Color.White
End If
'Checking the property of item in DataSet
If isDisabled(e.Index) Then
myFont = New Font(Me.Font, FontStyle.Strikeout)
myForeColor = Color.Gray
myBackColor = Color.WhiteSmoke
End If

myBrush = New SolidBrush(myBackColor)
e.Graphics.FillRectangle(myBrush, e.Bounds)
myBrush = New SolidBrush(myForeColor)
e.Graphics.DrawString(ListBox1.Items(e.Index), myFont, myBrush, New RectangleF(e.Bounds.X, _
e.Bounds.Y, e.Bounds.Width, e.Bounds.Height))
e.DrawFocusRectangle()
End Sub
Private Function isDisabled(ByVal Index As Integer) As Boolean
For Each item As Integer In DisabledList
If item = Index Then Return True
Next
End Function
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
If isDisabled(Me.ListBox1.SelectedIndex) Then Me.ListBox1.SelectedIndex += 1
End Sub
End Class

vaheeed
یک شنبه 01 اردیبهشت 1392, 14:17 عصر
داداش فکر کردم جستجو کردی جایی پیدا نکردی !!!
http://www.codeproject.com/Articles/34776/A-listbox-with-disabled-items
http://www.codeproject.com/Articles/85079/Custom-List-Box-Control-with-Enable-Disable-Items

اولی راحتتره فکر کنم خودم زیاد روش کار نکردم فقط رفرنسش رو درست کردم جواب داد دیگه دورش نرفتم فکر میکنم با فایل dll اش راحت کارت راه بیفته