- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("");
else if (textBox[0].Text != "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%'", textBox[0].Text);
else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%'", textBox[1].Text);
else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text != "" && textBox[3].Text == "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[midname] LIKE '%{0}%'", textBox[2].Text);
else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text != "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("course={0}", textBox[3].Text);
else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text != "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("group={0}", textBox[4].Text);
else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%'", textBox[0].Text, textBox[1].Text);
else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text == "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%' and [midname] LIKE '%{1}%'", textBox[1].Text, textBox[2].Text);
else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[midname] LIKE '%{0}%' and course={1}", textBox[2].Text, textBox[3].Text);
else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text != "" && textBox[4].Text != "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("course={0} and group={1}", textBox[3].Text, textBox[4].Text);
else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text == "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%' and [midname] LIKE '%{2}%'", textBox[0].Text, textBox[1].Text, textBox[2].Text);
else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%' and [midname] LIKE '%{1}%' and course={2}", textBox[1].Text, textBox[2].Text, textBox[3].Text);
else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text != "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[midname] LIKE '%{0}%' and course={1} and group={2}", textBox[2].Text, textBox[3].Text, textBox[4].Text);
else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%' and [midname] LIKE '%{2}%' and course={3}", textBox[0].Text, textBox[1].Text, textBox[2].Text, textBox[3].Text);
else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text != "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%' and [midname] LIKE '%{1}%' and course={2} and group={3}", textBox[1].Text, textBox[2].Text, textBox[3].Text, textBox[4].Text);
else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text != "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%' and [midname] LIKE '%{2}%' and course={3} and group={4}", textBox[0].Text, textBox[1].Text, textBox[2].Text, textBox[3].Text, textBox[4].Text);
"Есть 5 текстовых полей и желание понять, как можно в зависимости от пустоты или заполненности этих полей, одного или нескольких создать малое количество операторов if else"
Порадовало "малое количество"