I have two combobox .. and i have some items in both combobox
now i need to check the item in both combobox if same item
is Present in both combobox i need to display that item in
message box
Answers were Sorted based on User's Feedback
Answer / pavel
bool found = false;
string item = string.Empty;
foreach (string item1 in comboBox1.Items)
{
foreach (string item2 in comboBox2.Items)
if (item1 == item2)
{
item = item1;
found = true;
break;
}
if (found) break;
}
MessageBox.Show(found ? item : "Not found");
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / kirupa
for (int i = 0; i <= comboBox1.Items.Count-1; i++)
{
for (int j = 0; j <= comboBox2.Items.Count-1; j++)
{
if (comboBox1.Items[i].ToString() == comboBox2.Items
[j].ToString())
MessageBox.Show(comboBox1.Items[i].ToString());
}
}
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / rejeesh
foreach (string item1 in comboBox1.Items)
{
foreach (string item2 in comboBox2.Items)
if (item1 == item2)
{
MessageBox.Show(item1);
}
}
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / somnath
int countFirstBox=comboBox1.Items.Count;
int countSecondBox=comboBox2.Items.Count;
if(countFirstBox==countSecondBox)
{
MessageBox.Show(comboBox1.Items);
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / atiullah siddique
for (int i = 0; i <= comboBox1.Items.Count-1; i++)
{
for (int j = 0; j <= comboBox2.Items.Count-1; j++)
{
if (comboBox1.Items[i].ToString() == comboBox2.Items
[j].ToString())
MessageBox.Show(comboBox1.Items[i].ToString());
}
}
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / guest
Compare the values in both the comboboxes :
if(comboBox1.Text == comboBox2.Text)
{
MessageBox.Show(comboBox1.Text);
}
Is This Answer Correct ? | 7 Yes | 8 No |
Answer / cutee
/* C# Version */
for (int i=0; i<= ComboBox1.Items.Count)
{
for(int j=0 ; j<= ComboBox2.Items.count)
{
if (ComboBox1.Items[i].Text == ComboBox2.Items
[j].Text)
MessageBox.Show(Items[i].Text);
}
}
Is This Answer Correct ? | 3 Yes | 6 No |
Answer / mona
For inti As Integer = 0 To ComboBox1.Items.Count
For intj As Integer = 0 To ComboBox2.Items.Count
If ComboBox1.Items(inti).ToString =
ComboBox2.Items(intj).ToString Then
MessageBox.Show(ComboBox1.Items(inti))
End If
Next
Next
The answer should be modified. The loop should not go upto
the count-1 but should go upto count. Rest all is OK.
Is This Answer Correct ? | 1 Yes | 8 No |
What is the extension of the windows installer file?
HOW TO NET FORMS THE WINDOWS
What is the full form of gac?
How do you check whether the row data has been changed?
What is form and its types?
What are windows based applications examples?
Name the property which is used to lock a textbox to enter data?
what are the types of combo box?
how to create a set up in vb.net for desktop application please say me steps with examples
Name the class to be inherited for creating a custom control.
What is window form application?
How to show a ContextMenuStrip instead of cthe default ContextMenuStrip,when you rightclick on the non client area of a window's Form or when alt+space keys are pressed