-1
TextBoxで導入されたテキストをDataGridViewで検索するプログラムを作成しようとしています。 Idはある時点まで働く。 私は別のTextBoxに見つかった値を書きたいが、それはそのTextBox "-1"に書き込むことだけである。どうして?私は何かを逃しているのですか、何か間違っていますか?DataGridViewでデータを検索する - C#
private void PopulateDataViewAndFind()
{
DataSet set1 = new DataSet();
string sourceXml = "<?xml version='1.0' encoding='UTF-8'?>" +
"<music>" +
"<recording><artist>Coldplay</artist><cd>X&Y</cd></recording>" +
"<recording><artist>Dave Matthews</artist><cd>Under the Table and Dreaming</cd></recording>" +
"<recording><artist>Natalie Merchant</artist><cd>Tigerlily</cd></recording>" +
"<recording><artist>U2</artist><cd>How to Dismantle an Atomic Bomb</cd></recording>" +
"</music>";
StringReader reader = new StringReader(sourceXml);
set1.ReadXml(reader);
DataTableCollection tables = set1.Tables;
DataView view1 = new DataView(tables[0]);
BindingSource source1 = new BindingSource();
source1.DataSource = view1;
dataGridView1.DataSource = source1;
int itemFound = source1.Find("artist", textBox1.Text);
source1.Position = itemFound;
string cdFound = source1.Find("cd", textBox1.Text).ToString();
textBox2.Text = cdFound;
}
助けてください、ありがとう:
は、ここに私のコードです! :)
何あなたのDataGrid内のオブジェクトがどのように見えるのですか? |アーティスト名: – Ciphra
|曲名例:U2 |原子爆弾を解体する方法。 – DannyDSB
はい、それは '文字列' 'U2 |原子爆弾の解体方法 'ですか、' Artist'プロパティと 'CD'プロパティを持つ' Recording'オブジェクトですか? – Ciphra