First off, why are you converting everything to a string at all, let alone multiple times?
If you can only compare items via strings - which is a bad idea - then convert them once and then compare those:
string id1 = cmbcam1Id.SelectedItem.ToString();
string id2 = cmbcamera2Id.SelectedItem.ToString();
string id3 = cmbcamera3Id.SelectedItem.ToString();
string type1 = cmbcamera1Id.SelectedItem.ToString();
string type2 = cmbcamera2Id.SelectedItem.ToString();
string type3 = cmbcamera2Id.SelectedItem.ToString();
Your existing code them becomes a lot more readable:
if (id1 == id2 && type1 == type2)
{
I'd also suggest that you change the way you do it: a single "is it duplicated?" test is a lot easier to work with :
if ((id1 == id2 && type1 == type2) ||
(id1 == id3 && type1 == type3) ||
(id2 == id3 && type2 == type3))
{
MessageBox.Show("Duplicate not allowed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
...
}
And do yourself a favour: use the same name format throughout ...
cmbcam1Id
,
cmbcamera2Id
, and
cmbcamera3Id
looks like it was written by a student ...