PersonListView
-Modal형 AddDialog
-Modeless형 FindDialog
PersonListView
-Modal형 AddDialog
-Modeless형 FindDialog
public void Sort(Comparison<T> comparison)
http://msdn.microsoft.com/en-us/library/w56d4y5z.aspx
List<Person> pList = new List<Person>();
pList.Sort(ComparePersonByID); // pList를 ID로 정렬하기
[…]
public class Person : IComparable<Person>
{
public static Comparison<Person> ComparePersonByID =
delegate(Person p1, Person p2)
{
return p1.ID.CompareTo(p2.ID);
};
[…]
}
pList.Sort(ComparePersonByID); // pList를 ID로 정렬하기 (Comparison delegate)
public class Person : IComparable<Person>
{
public static Comparison<Person> ComparePersonByID =
delegate(Person p1, Person p2)
{
return p1.ID.CompareTo(p2.ID);
};
[…]
}
pList.Sort(new PersonIDComparer()); // pList를 ID로 정렬하기 (IComparer)
public class PersonIDComparer : IComparer<Person>
{
public int Compare(Person p1, Person p2)
{
return p1.ID.CompareTo(p2.ID);
}
}
pList.Sort((p, q) => p.ID.CompareTo(q.ID)); // pList를 ID로 정렬하기 (lambda)
RSS 2.0 Specification
http://cyber.law.harvard.edu/rss/rss.html
How to: Sort ListView Items
http://msdn.microsoft.com/en-us/library/ms229643(VS.80).aspx
class ListViewItemComparer : IComparer
{
private int column;
public ListViewItemComparer() : this(0) {}
public ListViewItemComparer(int column)
{
this.column = column;
}
public int Compare(object x, object y) // string compare
{
return String.Compare(((ListViewItem)x).SubItems[column].Text,
((ListViewItem)y).SubItems[column].Text);
}
}
/////
public partial class Form1 : Form
{
[…]
private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
{
// Set the column number that is to be sorted; default to ascending.
this.listView1.ListViewItemSorter = new ListViewItemComparer(e.Column);
// Perform the sort with these new sort options.
this.listView1.Sort();
}
}
텍스트 박스에 “12.5”, “.3”, “-12” 등과 같은 양수/음수의 double 숫자만 입력받을 수 있도록 하려면
(그외에 “abcd”같은 문자나 “12.3.4” 같은 이상한 숫자는 입력받을 수 없도록하기위해)
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// accept only digit(0-9) with ‘.’ (dot) and ‘-‘ (minus)
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != ‘.’ && e.KeyChar != ‘-‘)
e.Handled = true;
// accept only one decimal point (.32)
if (e.KeyChar == ‘.’ && (sender as TextBox).Text.IndexOf(‘.’) > -1)
e.Handled = true;
// accept only minus sign at the beginning
if (e.KeyChar == ‘-‘ && (sender as TextBox).Text.Length > 0)
e.Handled = true;
}
Lecture13
Lecture12
Lecture11
Lecture10