DataView
의 경우 DataTable
의 CaseSensitive
속성을 true로 설정하면됩니다. A는 대소 문자를 구분하는 찾기 구현하는 기본 목록을 당신이 필요로하는 IBindingList의 다른 유형의
public Form1()
{
InitializeComponent();
DataSet set1 = new DataSet();
// Some xml data to populate the DataSet with.
string testXml =
"<?xml version='1.0' encoding='UTF-8'?>" +
"<numbers>" +
"<number><name>one</name></number>" +
"<number><name>two</name></number>" +
"<number><name>Two</name></number>" +
"<number><name>three</name></number>" +
"</numbers>";
// Read the xml.
StringReader reader = new StringReader(testXml);
set1.ReadXml(reader);
// Get a DataView of the table contained in the dataset.
DataTableCollection tables = set1.Tables;
// Set the CaseSensetive property
tables[0].CaseSensitive = true;
DataView view1 = new DataView(tables[0]);
// Create a DataGridView control and add it to the form.
dataGridView1.AutoGenerateColumns = true;
// Create a BindingSource and set its DataSource property to
// the DataView.
BindingSource source1 = new BindingSource();
source1.DataSource = view1;
// Set the data source for the DataGridView.
dataGridView1.DataSource = source1;
// Set the Position property to the results of the Find method.
int itemFound = source1.Find("name", "Two");
source1.Position = itemFound;
}
을, 워드 프로세서 말하는대로 : 난 그냥 빨리 다음 코드를 사용하는 것이 프로토 타입과 잘 작동합니다. 완성도를 위해 내가 아래에이 작업을 수행하는 코드를 보여 주었다 :
public Form1()
{
InitializeComponent();
// This uses my CaseSensitiveBindingList which I have code for later
BindingList<DGVItems> source = new CaseSensitiveBindingList<DGVItems>()
{
new DGVItems { Number = "one" },
new DGVItems{Number = "two"},
new DGVItems{Number = "Two"}
};
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = source;
dataGridView1.DataSource = bindingSource;
var index = bindingSource.Find("Number", "Two");
// Index is 2 (third item) as desired.
MessageBox.Show(number.ToString());
}
public class DGVItems
{
public string Number { get; set; }
}
그리고 CaseSensitiveBindingList에 대한 코드입니다 :
public class CaseInsensitiveBindingList<T> : BindingList<T>
{
protected override int FindCore(PropertyDescriptor prop, object key)
{
string stringKey = key as string;
bool keyIsString = stringKey != null;
for (int i = 0; i < Count; ++i)
{
if (keyIsString && prop.PropertyType.IsAssignableFrom(typeof(string)))
{
if (stringKey.Equals(prop.GetValue(Items[i]).ToString(), StringComparison.CurrentCulture))
return i;
}
else
{
if (key.Equals(prop.GetValue(Items[i])))
return i;
}
}
return -1;
}
}
그 코드는 거의 확실하게 개선하지만, 일반적인 개념을 표시 할 수있다.
아직이 솔루션을 찾을 수 없었습니다. 문서를 조금 더 다음 : DataView (나는 내 기본 목록 믿습니다)이 IBindingList.Find를 호출합니다. 대/소문자를 구분하는지 여부는 알 수 없지만 사용자 지정 검색을 사용하는 클래스를 만드는 예가 있습니다. http://msdn.microsoft.com/en-us/library/system.componentmodel.ibindinglist.find.aspx 이 예제를 사용하여 대소 문자가 아닌 DataView에 대한 사용자 지정 검색을 만들 수 있어야합니다. 민감하지만, 어디서부터 시작해야할지 모르겠다. 누구나 접근법을 제안 할 수 있습니까? – shindigo