contents of combo box shown in list box - c#

I was wondering, if I click a selection on a ComboBox for instance letter A, and I want its content to show in label or ListBox, how can I do that? I tried experimenting with some codes below. This codes below are not working for me. any other way or suggestion?
private void selectContents_SelectedIndexChanged(object sender, System.EventArgs e)
{
string var;
var = selectContents.Text;
if (var == "A")
{
Label1.Text = "hi";
listBox1.Text = "hi";
}
}
ok problem solve i just need to change the var :D

you can't have string var;
var is a keyword in c# MSDN C# keywords
I have no clue how that code was compiling, I suppose it wasn't
edit
string a = "var"; //this is ok
string var = "a"; //this is not

I believe this is what you're looking for.
private void selectContents_SelectedIndexChanged(object sender, System.EventArgs e)
{
listBox1.Items.Add(selectContents.SelectedItem);
Label1.Text = selectContents.SelectedItem;
}

Related

bunifu material textbox mode password is not working

I want to create a login page based C# desktop application. I use the bunifu toolbox to create a login page design. But when I want to create a password field using the bunifumaterialtextbox, the textbox does not show any changes / it only displays alphabet. It looks like the ispassword contained in the textbox properties is not working. So what should I do so that this texbox can display the correct password (not displaying alphabeth) when the program is run ?. I apologize for any errors in this question.
is just a easy solution i have found
private void passbox_OnValueChanged(object sender, EventArgs e)
{
passbox.isPassword = true;
}
I'm new using the Bunifu framework tool and I had the same problem then you. The solution I found was to invoke the _TextBox method which I suppose that gives you all the normal TextBox controls.
My code was something like this:
txtPassword._TextBox.PasswordChar = '*';
I loaded this code inside the Form_Load code block. It worked for me, hope that be useful for you too. Good luck!
in side the properties tab of the bunifu text box there is a property ispassword set it to true.
to fully make the bunifu textbox to passwordbox you have to do the following:
1.in side the properties tab of the bunifu text box there is a property ispassword set it to False.
2.create an event of Enter and use the following code:
3.create an event of Leave and use the following code:
private void txtpassword_Enter(object sender, EventArgs e)
{
if (txtpassword.Text == "Password")
{
txtpassword.Text = "";
txtpassword.isPassword = true;
}
}
private void txtpassword_Leave(object sender, EventArgs e)
{
if (txtpassword.Text == "")
{
txtpassword.Text = "Password";
txtpassword.isPassword = false;
}
}
like this
You can use the UseSystemPasswordChar property in your text box.
Example:
TextBox1.UseSystemPasswordChar = true;
this problem's solution is using enter,leave and textchange event such as below code if the name of your text box is txtPassword:
private void txtPassword_TextChange(object sender, System.EventArgs e)
{
if (txtPassword.Text.Trim() != "")
{
txtPassword.PasswordChar = '*';
}
else
{
txtPassword.PasswordChar = '\0';
}
}
private void txtPassword_Leave(object sender, System.EventArgs e)
{
if (txtPassword.Text.Trim() == "")
{
txtPassword.PasswordChar = '\0';
txtPassword.TextPlaceholder = "insert your placeholder..";
}
}
private void txtPassword_Enter(object sender, System.EventArgs e)
{
if (txtUserName.Text.Trim() != "")
{
txtPassword.PasswordChar = '*';
txtPassword.PlaceholderText = "";
}
}

How to bind suggestions with text box with first and last name?

IDE: C#.net, Winforms, .net 4.0
I want to bind a text box with suggestions, suggestions will come from a list, that list is having space separated words for example 'Little Jhon' now with the help of following code I have implemented suggestion functionality, but I want when user type anything suggestions should come from both words, currently it is coming from first word only.
Code:
private void BindTournamentNames()
{
//On Load Code
List<String> lstNames= new List<string>();
lstNames.Add("Little John");
lstNames.Add("Hello Yogesh");
var source = new AutoCompleteStringCollection();
txtBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
source.AddRange(lstNames.ToArray());
txtBox1.AutoCompleteCustomSource = source;
txtBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
txtBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
Now when I am typing in textBox 'Little' it is giving me suggestion, but when I am typing John it is not giving me suggestion, please tell me how to do this.
Well existing autoComplete functionality only supports searching by prefix. I have the same requirement in one of my project. So what i had done is -
Added a ListBox just below the TextBox and set its default visibility to false. Then use the OnTextChanged event of the TextBox and the SelectedIndexChanged event of the ListBox to display and select the items. like this -
Note: Assume your BindTournamentNames() method called in Form's constructor.
protected void textBox1_TextChanged(object sender, System.EventArgs e)
{
listBox1.Items.Clear();
if (textBox1.Text.Length == 0)
{
listBox1.Visible = false;
return;
}
foreach (String s in textBox1.AutoCompleteCustomSource)
{
if (s.Contains(textBox1.Text))
{
listBox1.Items.Add(s);
listBox1.Visible = true;
}
}
}
protected void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
textBox1.Text = listBox1.Items[listBox1.SelectedIndex].ToString();
listBox1.Visible = false;
}
good luck...

String.ToUpper does not capitalize string when passing to DevExpress TextEdit control

Can someone explain me why first code block doesn't work while second one does. In first example string is not capizalized when control lose focus.
Don't work (not capitalized):
private void nameTextEdit_Leave(object sender, EventArgs e)
{
if(Properties.Settings.Default.capitalizeCustomer != false)
{
string userEnteredString = nameTextEdit.EditValue.ToString();
string capitalizedString = userEnteredString.ToUpper();
nameTextEdit.EditValue = capitalizedString;
}
}
Work's OK (when control lost focus text is capitalized):
private void nameTextEdit_Leave(object sender, EventArgs e)
{
if(Properties.Settings.Default.capitalizeCustomer != false)
{
string userEnteredString = nameTextEdit.EditValue.ToString();
nameTextEdit.EditValue = userEnteredString.ToUpper();
}
}
This is strange, both examples should have the same effect.
My best guess is you accidentally did
nameTextEdit.EditValue = userEnteredString;
Instead of:
nameTextEdit.EditValue = capitalizedString;
Why don't you simply set CharacterCasing property to Upper and prevent lower case from the start?

C# Need Help Changing a Label.Text - My Function/method won't change my Form Label Text

I wanted to make a function to organize my code better but this is giving me a headache, My Problem is that I want to use my Public Function to change the label.Text whenever I call them from the Form but it's not working. How can I get this working and please be very basic. Thank You.
Here's my Code:
namespace NoSleepHD
{
public partial class NoSleepHD : Form
{
public NoSleepHD()
{
InitializeComponent();
}
public void selectFolder(string driveLabel, string writePath)
{
FolderBrowserDialog Tree = new FolderBrowserDialog();
Tree.RootFolder = Environment.SpecialFolder.MyComputer;
Tree.ShowNewFolderButton = false;
Tree.Description = "Please Select any Drive OR Folder on Your External hard Drive";
Tree.ShowDialog();
if (Tree.SelectedPath.Length != 0)
{
driveLabel = Tree.SelectedPath.ToString();
Properties.Settings.Default.WritePath01 = driveLabel.ToString();
Properties.Settings.Default.Save();
}
}
private void Button1_Click(object sender, EventArgs e)
{
selectFolder(Label11.Text, Properties.Settings.Default.WritePath01);
}
but Label11.Text does not show any Text. Can someone kind please help me out. Thank You.
Of course it wouldn't: you're passing a string Label11.Text to the function. Pass the Label11 object only and set its text in the selectFolder function.
Ok. If you have 10 labels that are linked to folder locations, it would be better to do it this way (notice that the Click handler is using sender, so you can use this handler for all the label buttons, no need for separate handlers).
public void selectFolder(Label label, string writePath)
{
FolderBrowserDialog Tree = new FolderBrowserDialog();
Tree.RootFolder = Environment.SpecialFolder.MyComputer;
Tree.ShowNewFolderButton = false;
Tree.Description = "Please Select any Drive OR Folder on Your External hard Drive";
Tree.ShowDialog();
if (Tree.SelectedPath.Length != 0)
{
label.Text = Tree.SelectedPath.ToString();
Properties.Settings.Default.WritePath01 = label.Text;
Properties.Settings.Default.Save();
}
}
private void FolderSelector_Click(object sender, EventArgs e)
{
selectFolder(sender as Label, Properties.Settings.Default.WritePath01);
}

How can I transfer text from one textbox to another textbox without it looping and not sending the text?

I have searched for what I am asking of you but I may have been wording it wrong, so I hope what I have typed is easy to understand.
I am creating a Css formatter with two textboxes using WinForms
I would like it to take a css long format code in the first textBoxLongFormat then appear in the second, textboxShortFormat, as css short code.
I have a bit of code for both text boxes and a separate class of other code for the behind the scenes to change the format.
The class works but I’m having a problem with textBoxLongFormat and I’m guessing it will happen the other way round, the code is looping on its self and not closing, so it’s not sending the format to textBoxShortFormat so nothing happens.
There is something I am doing wrong, I know, but I cannot see it. What is it that I am doing wrong? It will be great to have your help.
Here is the code for the textboxes if it helps.
What is it that i need to add or to make it work?
private void textBoxLongFormat_TextChanged(object sender, EventArgs e)
{
CssFormatConverter cssLongFormatConverter = new CssFormatConverter();
string longFormatCss = textBoxLongFormat.Text;
string shortFormatCss = cssLongFormatConverter.ToShortFormat(longFormatCss);
textBoxShortFormat.Text = shortFormatCss;
}
private void textBoxShortFormat_TextChanged(object sender, EventArgs e)
{
CssFormatConverter cssShortFormatConverter = new CssFormatConverter();
string shortFormatCss = textBoxShortFormat.Text;
string longFormatCss = cssShortFormatConverter.ToLongFormat(shortFormatCss);
textBoxLongFormat.Text = longFormatCss;
}
Thank you in advance
Add a boolean check that indicates the other textbox is updating.
bool isUpdating = false;
private void textBoxLongFormat_TextChanged(object sender, EventArgs e)
{
if (!isUpdating)
{
isUpdating = true;
CssFormatConverter cssLongFormatConverter = new CssFormatConverter();
string longFormatCss = textBoxLongFormat.Text;
string shortFormatCss = cssLongFormatConverter.ToShortFormat(longFormatCss);
textBoxShortFormat.Text = shortFormatCss;
isUpdating = false;
}
}
private void textBoxShortFormat_TextChanged(object sender, EventArgs e)
{
if (!isUpdating)
{
isUpdating = true;
CssFormatConverter cssShortFormatConverter = new CssFormatConverter();
string shortFormatCss = textBoxShortFormat.Text;
string longFormatCss = cssShortFormatConverter.ToLongFormat(shortFormatCss);
textBoxLongFormat.Text = longFormatCss;
isUpdating = false;
}
}
Before updating a TextBox, unsubscribe it from the TextChanged event. Then update. Then re-subscribe.
In the first one, that would be:
textBoxShortFormat.TextChanged -= textBoxShortFormat_TextChanged;
textBoxShortFormat.Text = shortFormatCss;
textBoxShortFormat.TextChanged += textBoxShortFormat_TextChanged;

Categories