- ½Ã½ºÅÛ À̹ÌÁö ¸®½ºÆ® »ç¿ëÇϱâ
- ListView ¼º´É °³¼±
- ListView °¢ Ä÷³ Çì´õ Ŭ¸¯½Ã ÇØ´ç Ä÷³À» ±âÁØÀ¸·Î ¾ÆÀÌÅÛ Á¤·ÄÇϱâ
- TextBox ¸¶Áö¸· ¶óÀαîÁö ½ºÅ©·Ñ Çϱâ
- Mnemonic Focus Control
1 ½Ã½ºÅÛ À̹ÌÁö ¸®½ºÆ® »ç¿ëÇϱâ
2 ListView ¼º´É °³¼±
Á¤·ÄÀÚ(sorter)°¡ ¼³Á¤µÇ¾î ÀÖ´Â ¸®½ºÆ®ºä¿¡ ´ë·®ÀÇ ¾ÆÀÌÅÛÀ» Áý¾î³Ö´Â °æ¿ì, ¾ÆÀÌÅÛÀ» Áý¾î³ÖÀ» ¶§¸¶´Ù Á¤·ÄÀÌ ÀÌ·ç¾îÁö¹Ç·Î µÚ·Î °¥¼ö·Ï ¸Å¿ì ´À·ÁÁø´Ù. À̸¦ ÇØ°áÇϱâ À§Çؼ´Â 2°¡Áö ¹æ¹ýÀÌ ÀÖ´Ù.
ù¹øÂ°´Â ¾ÆÀÌÅÛÀ» Áý¾î³Ö±â Àü¿¡ Á¤·ÄÀÚ¸¦ null·Î ¸¸µç ´ÙÀ½, ´Ù Áý¾î³ÖÀº ÈÄ Á¤·ÄÀÚ¸¦ »õ·Î ¼¼ÆÃÇϰí, Sort()¸¦ È£ÃâÇÏ´Â ¹æ¹ýÀÌ´Ù. ¾ÆÀÌÅÛÀ» Áý¾î³ÖÀ» ¶§ AddRange() ÇÔ¼ö¸¦ ÀÌ¿ëÇϸé Á» ´õ ³ªÀº ¼º´ÉÀ» ¾òÀ» ¼ö ÀÖ´Ù.
System.Collections.IComparer<ListViewItem> oldSorter = MyListView.ListViewItemSorter;
MyListView.ListViewItemSorter = null;
...
¾ÆÀÌÅÛ Ãß°¡
...
MyListView.ListViewItemSorter = oldSorter;
MyListView.Sort();
µÎ¹øÂ°´Â ¸®½ºÆ®ºäÀÇ °¡»ó ¸ðµå(virtual mode)¸¦ ÀÌ¿ëÇÏ´Â ¹æ¹ýÀÌ´Ù. °¡»ó ¸ðµå¿¡¼´Â ¾ÆÀÌÅÛÀÇ Ä÷º¼ÇÀÌ ¸®½ºÆ®ºä ³»ºÎ¿¡ Á¸ÀçÇÏ´Â °ÍÀÌ ¾Æ´Ï¶ó, ¿ÜºÎ¿¡ Á¸ÀçÇÏ°Ô µÈ´Ù. ¸®½ºÆ®ºä°¡ À̺¥Æ® Çڵ鷯¸¦ ÅëÇØ ¾ÆÀÌÅÛÀ» ¿äûÇϸé À¯Àú°¡ À̸¦ Á¦°øÇØÁà¾ß ÇÑ´Ù.
...
TListViewItem[] MyItems;
MyListView.OnRetrieveVirtualItem += MyListView_RetrieveVirtualItem;
...
private void SomeButton_Click(object sender, EventArgs e)
{
Array.Sort(MyItems, MySorter);
MyListView.VirtualMode = true;
MyListView.VirtualListSize = MyItems.Length;
}
private void MyListView_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
e.Item = MyItems[e.ItemIndex];
} Á¤·ÄÀÚ ¾È¿¡¼ ÇÏ´Â ÀÏÀÌ ¸Å¿ì ¸¹´Ù¸é, Áï ¸®½ºÆ® ¾ÆÀÌÅÛ ºñ±³¿¡ µé¾î°¡´Â ºñ¿ëÀÌ Å©´Ù¸é °¡»ó ¸ðµåº¸´Ù´Â ±×³É Á¤·ÄÀÚ ²°´Ù ÄÖ´Ù ÇÏ´Â °ÍÀÌ ³´´Ù.
3 ListView °¢ Ä÷³ Çì´õ Ŭ¸¯½Ã ÇØ´ç Ä÷³À» ±âÁØÀ¸·Î ¾ÆÀÌÅÛ Á¤·ÄÇϱâ
´ëÃæ ¾Æ·¡¿Í °°Àº Ŭ·¡½º¸¦ ¸¸µé°í...
/// <summary>
/// ¸®½ºÆ®ºä ¾ÆÀÌÅÛ ¼ÒÆÃÀ» À§ÇÑ ºñ±³ Ŭ·¡½º.
/// ¸®½ºÆ®ºä¿¡ ÀÖ´Â ¾ÆÀÌÅÛÀ» ¹®ÀÚ¿·Î¼°¡ ¾Æ´Ï¶ó, ¼ýÀÚ·Î ºñ±³ÇϰíÀÚ ÇÏ´Â
/// °æ¿ì Numeric = true·Î ¼³Á¤ÇÑ´Ù.
/// </summary>
class ListViewItemComparer : System.Collections.IComparer<ListViewItem>
{
private int ColumnIndex = 0;
private bool NumericComparison = false;
private bool AscendingOrder = true;
public int Column
{
get { return ColumnIndex; }
set { ColumnIndex = value; }
}
public bool Numeric
{
get { return NumericComparison; }
set { NumericComparison = value; }
}
public bool Ascending
{
get { return AscendingOrder; }
set { AscendingOrder = value; }
}
public ListViewItemComparer(int col)
{
ColumnIndex = col;
}
public int Compare(object l, object r)
{
ListViewItem lhs = (ListViewItem)l;
ListViewItem rhs = (ListViewItem)r;
if (AscendingOrder)
{
if (lhs == null && rhs == null) return 0;
else if (lhs == null) return -1;
else if (rhs == null) return 1;
if (lhs == rhs) return 0;
if (NumericComparison)
{
decimal lhsValue, rhsValue;
if (!Decimal.TryParse(lhs.SubItems[ColumnIndex].Text, out lhsValue))
lhsValue = 0;
if (!Decimal.TryParse(rhs.SubItems[ColumnIndex].Text, out rhsValue))
rhsValue = 0;
return Decimal.Compare(lhsValue, rhsValue);
}
else
{
string lhsText = lhs.SubItems[ColumnIndex].Text;
string rhsText = rhs.SubItems[ColumnIndex].Text;
return String.Compare(lhsText, rhsText);
}
}
else
{
if (lhs == null && rhs == null) return 0;
else if (lhs == null) return 1;
else if (rhs == null) return -1;
if (lhs == rhs) return 0;
if (NumericComparison)
{
decimal lhsValue, rhsValue;
if (!Decimal.TryParse(lhs.SubItems[ColumnIndex].Text, out lhsValue))
lhsValue = 0;
if (!Decimal.TryParse(rhs.SubItems[ColumnIndex].Text, out rhsValue))
rhsValue = 0;
return -(Decimal.Compare(lhsValue, rhsValue));
}
else
{
string lhsText = lhs.SubItems[ColumnIndex].Text;
string rhsText = rhs.SubItems[ColumnIndex].Text;
return -(String.Compare(lhsText, rhsText));
}
}
}
};
// ¾îµò°¡¿¡¼ À̺¥Æ® Çڵ鷯 Ãß°¡ÇØÁÖ°í...
...
ListView1.ColumnClick += ListView1_ColumnClick;
...
private void ListView1_ColumnClick(object sender, ColumnClickEventArgs e)
{
ListViewItemComparer sorter =
ListView1.ListViewItemSorter as ListViewItemComparer;
if (sorter == null)
sorter = new ListViewItemComparer(e.Column);
else
sorter.Column = e.Column;
ListView1.Sort();
}
4 TextBox ¸¶Áö¸· ¶óÀαîÁö ½ºÅ©·Ñ Çϱâ
·Î±× Ãâ·Â °°Àº °É ÅØ½ºÆ®¹Ú½º¿¡´Ù ÇÏ´Â °æ¿ì, ÅØ½ºÆ®°¡ Ãß°¡µÉ ¶§¸¶´Ù ¸¶Áö¸· ¶óÀαîÁö ½ºÅ©·ÑÇØÁÖ´Â °ÍÀÌ º¸±â°¡ ÁÁ´Ù. À̸¦ À§Çؼ´Â TextBox.ScrollToCaret ÇÔ¼ö¸¦ ÀÌ¿ëÇÏ¸é µÈ´Ù. ´Ü Æ÷Ä¿½º¸¦ ÅØ½ºÆ®¹Ú½º¿¡´Ù Áà¾ßÇÑ´Ù.
TextBox1.Focus();
TextBox1.SelectionStart = TextBox1.TextLength;
TextBox1.ScrollToCaret();
5 Mnemonic Focus Control
Label°ú Textbox°¡ ÀÖÀ» ¶§ ¶óº§¿¡ ÀÖ´Â mnemonicÀ» ´·¶À» ¶§, Textbox¿¡ Æ÷Ä¿½º°¡ °¡°Ô ÇÏ·Á¸é, ÅǼø¼¸¦ Àß ¸ÂÃçÁÖ¸é µÈ´Ù.
»ç¿ëÀÚ°¡ ALT+S¸¦ ´©¸£¸é ÀÏ´Ü ÇØ´çÇÏ´Â ¶óº§¿¡ Æ÷Ä¿½º¸¦ ÁÖ·Á°í ½ÃµµÇÑ´Ù. ±×·±µ¥ ¶óº§Àº ±âº»ÀûÀ¸·Î Æ÷Ä¿½º¸¦ °¡Áú ¼ö ¾øÀ¸¹Ç·Î ±× ´ÙÀ½ ÄÁÆ®·Ñ¿¡ Æ÷Ä¿½º°¡ °¡°Ô µÈ´Ù. ±×·¡¼ ¿øÇÏ´Â ÄÁÆ®·Ñ¿¡ Æ÷Ä¿½º°¡ °¡°Ô µÇ´Â °ÍÀÌ´Ù. ¸¸¾à ±× ´ÙÀ½ ÄÁÆ®·ÑÀÌ Æ÷Ä¿½º¸¦ °¡Áú ¼ö ¾ø´Â ÄÁÆ®·ÑÀ̶ó¸é °è¼ÓÇØ¼ ´ÙÀ½ ÄÁÆ®·ÑÀ» ½ÃµµÇÏ°Ô µÈ´Ù.
SeriousMoin v1 (koMoinMoin 1.0a4 Modified)