我需要隱藏複選框只從指定的行。這是可能的和如何?如何從列表視圖中隱藏複選框
2
A
回答
0
您將需要實現一個自繪的ListBox。我有一個顯示所有項目的圖標和複選框,但是您可以輕鬆修改它以僅顯示特定項目的複選框。
public class IconizedCheckedListBox : ListBox
{
public IconizedCheckedListBox()
: base()
{
DrawMode = DrawMode.OwnerDrawVariable;
DoubleBuffered = true;
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
using (SolidBrush b = new SolidBrush(BackColor))
g.FillRectangle(b, e.Bounds);
//e.DrawBackground();
//e.DrawFocusRectangle();
if (e.Index < Items.Count && e.Index != -1)
{
IconizedCheckedListBoxItem item = (IconizedCheckedListBoxItem)Items[e.Index];
Rectangle checkBounds = e.Bounds;
checkBounds.X += kCheckboxPadding;
checkBounds.Y += (checkBounds.Height - kCheckboxSize)/2;
checkBounds.Width = kCheckboxSize;
checkBounds.Height = kCheckboxSize;
CheckBoxRenderer.DrawCheckBox(g, checkBounds.Location,
item.Checked?CheckBoxState.CheckedNormal:CheckBoxState.UncheckedNormal);
using (SolidBrush b = new SolidBrush(ForeColor))
{
StringFormat format = new StringFormat();
format.LineAlignment = StringAlignment.Center;
format.Alignment = StringAlignment.Near;
Rectangle textBounds = e.Bounds;
textBounds.X += item.Icon.Width + 2*kCheckboxPadding + kCheckboxSize;
textBounds.Y += 1;
textBounds.Width -= item.Icon.Width;
textBounds.Height -= 1;
Font f;
if (item.Checked)
f = new Font(Font, FontStyle.Bold);
else
f = Font;
g.DrawString(item.Data.ToString(), f, b, textBounds, format);
}
Image icon;
if (!item.Checked)
icon = Utilities.Utilities.WashOutImage(item.Icon);
else
icon = item.Icon;
g.DrawImage(icon, e.Bounds.X + 2 * kCheckboxPadding + kCheckboxSize, e.Bounds.Y);
}
}
protected override void OnMeasureItem(MeasureItemEventArgs e)
{
e.ItemHeight = kItemHeight;
}
protected override void OnMouseClick(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
int idx = IndexFromPoint(e.Location);
if (idx != -1)
{
IconizedCheckedListBoxItem item = (IconizedCheckedListBoxItem)Items[idx];
item.Checked = !item.Checked;
if (ItemCheck != null)
{
ItemCheckEventArgs args = new ItemCheckEventArgs(
idx,
item.Checked ? CheckState.Checked : CheckState.Unchecked,
CheckState.Indeterminate);
ItemCheck(this, args);
}
Invalidate();
}
}
base.OnMouseClick(e);
}
/// <summary>
/// This is called AFTER the check state has been updated
/// </summary>
public event ItemCheckEventHandler ItemCheck;
private const int kItemHeight = 32;
private const int kCheckboxSize = 13;
private const int kCheckboxPadding = 4;
}
public class IconizedCheckedListBoxItem
{
public IconizedCheckedListBoxItem(Image inIcon, object inData)
{
Icon = inIcon;
Data = inData;
Checked = false;
}
public override string ToString()
{
return Data.ToString();
}
public Image Icon;
public object Data;
public bool Checked;
}
1
相關問題
- 1. 在複選框列表中隱藏複選框ListItem的圖標
- 2. 從視圖列表中隱藏視圖
- 3. 用複選框顯示/隱藏視圖
- 4. 如何隱藏複選框列表中的未選項目?
- 5. 如何從代碼隱藏更新editItemTemplate複選框列表?
- 6. 隱藏複選框列表的文本
- 7. 隱藏選中複選框
- 8. 如何在複選框中隱藏和取消隱藏框
- 9. 複選框列表視圖
- 10. 如何隱藏表視圖中的自定義複選標記
- 11. 如何從p表格標題中隱藏/刪除複選框
- 12. 複選框中隱藏複選標記
- 13. 列表視圖中的複選框ABAP
- 14. 列表視圖中的Android複選框
- 15. 列表視圖中的複選框
- 16. 在列表視圖中隱藏列android
- 17. 獲取html複選框列表選中的值隱藏字段
- 18. 的javascript gridview的從隱藏字段和複選框列表
- 19. 基於複選框顯示和隱藏NewForm.aspx中的列表列
- 20. 如何在列表視圖中選擇適當的複選框
- 21. 在Kendo樹視圖中隱藏Root複選框
- 22. 如何隱藏複選框文本
- 23. 如何隱藏複選框標籤?
- 24. 在視圖中隱藏表中的列
- 25. 無法從列表視圖中挑選複選框
- 26. 從列表視圖中獲取複選框選定的值
- 27. 如何隱藏文本視圖從列表視圖中的列表視圖項在Android中
- 28. 如何從視圖中隱藏變量?
- 29. 圖像隱藏在複選框
- 30. 從DisplayFrom隱藏字段與複選框
OP要求提供「ListView」而不是「ListBox」。這不是一個有效的答案。 – Nick 2009-10-20 22:34:49