Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Comparing a combobox selected item With textbox1 if value same

then this should show
MessageBox.Show("Duplicate Entry", "OK!", MessageBoxButtons.OK, MessageBoxIcon.Information);

the textbox reads from listview1 columns
then must compare if the values are the same

then i can only
activate btnSave

What I have tried:

if (CboBINinout.SelectedItem == txtINOUT.Text)
{
btnOUT.Enabled = false;
}
Posted
Updated 30-Sep-18 11:23am
Comments
Richard MacCutchan 22-Sep-18 7:21am    
You need the value of the ComboBox item as a string, in order to compare it to the contents of the TextBox.

Try:
if (CboBINinout.SelectedText == txtINOUT.Text)
{
btnOUT.Enabled = false;
}
 
Share this answer
 
if (CboBINinout.SelectedItem.ToString().Trim() == txtINOUT.Text)
{
btnOUT.Enabled = false;
}
if (CboBINinout.SelectedItem.ToString().Trim() != txtINOUT.Text)
{
btnOUT.Enabled = true;
}
 
Share this answer
 
Comments
Richard Deeming 3-Oct-18 13:49pm    
Never heard of the else clause? :)

Or even shorter:
btnOUT.Enabled = (CboBINinout.SelectedItem.ToString().Trim() != txtINOUT.Text);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900