combobox.text += "sometext" dropdown - text

I want to choose from a drop-down list box, and add it in the combobox.text example "one;two;three"
how can I do it???
this code does not work because of the updates(((
FI_ComboBox[ii].SelectionChangeCommitted += (object sender, EventArgs e) =>
{
ComboBox FI_ComboBox1 = (ComboBox)sender;
FI_ComboBox1.BeginInvoke(new Action(() =>
{
FI_ComboBox1.Text += FI_ComboBox1.Items[FI_ComboBox1.SelectedIndex]+";";
}
));
};

Related

How to validate all the fields in c# in windows application?

I have a windows form it has 8 textboxes , 3 combobox and a radio button.
I am using this code but it does not work.
I put the beakpoint and checked the control does not go inside if(Cnt is TextBox) It is evaluating to false. I am keeping all the controls in the panel. May be because of this I am having a problem
private void button1_Click(object sender, EventArgs e)
{
foreach (Control cnt in this.Controls)
{
if (cnt is TextBox)
{
if (cnt.Text == "")
{
MessageBox.Show("TextBox is Blank.");
cnt.BackColor = Color.Pink;
}
}
else if (cnt is ComboBox)
{
ComboBox cmb = (ComboBox)cnt;
if (cmb.SelectedItem == null)
{
MessageBox.Show("Combox is not Selected.");
cnt.BackColor = Color.Plum;
}
}
}
}

KeyPressed in textbox not working

I tried to get the code below working, but to no avail.
I have to make a login window, and except from the Log in button I want by pressing the Enter key in password textbox the result to be the same. C# 2010.
private void button1_Click(object sender, EventArgs e)
{
int ok=0;
if (textBox1.Text == "administrator" && textBox2.Text == "administrator")
{
ok = 1;
this.Hide();
Admin admin = new Admin();
admin.ShowDialog();
}
if (textBox1.Text == "jucator" && textBox2.Text == "jucator")
{
ok = 1;
this.Hide();
}
if (ok == 0)
{
label2.Text = "nume user sau parola incorecta";
label2.Visible = true;
}
}
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
button1_Click(this, new EventArgs());
}
}
You should use the KeyUp event It's more reliable in you case.
Then check for the pressed key.
e.g.:
private void textBox2_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
//DoLogin... in your case it would be
button1_Click(null,null);
e.Handled = true;
}
else
{
e.Handled = false;
}
}
On a side note: I really discourage you to use that Log In method, comparing strings to a hardcoded strings is really a waste, there're better scenarios specially in an environment where you have multiple users Otherwise why would you require a login?

How to change text of a cell at runtime in XtraReport?

How to change text of a cell at runtime in XtraReport?
I am using "DevExpress v2011 vol 1".
I have a few cells and I can change their text one by one using PreviewClick event as below.
private void _cell_PreviewClick(object sender, PreviewMouseEventArgs e)
{
e.Brick.Text = "aaabbbccc"; e.PreviewControl.Refresh();
}
But, in that event I need to change text of other cells simultaneously. I tried below and got no luck
private void _cell_PreviewClick(object sender, PreviewMouseEventArgs e)
{
e.Brick.Text = "aaabbbcc";
otherCell1.Text = "rrrttcwwww"
e.PreviewControl.Refresh();
}
Best Regards,
Orgil.D
You can handle the DataSourceRowChanged event of the XtraReport Class
private void rpt_DataSourceRowChanged(object sender, DataSourceRowEventArgs e)
{
MyClass xx = bidingSource[e.CurrentRow] as MyClass ;
if (string.IsNullOrWhiteSpace(xx.WorkDescription))
{
xrTableCell25.Visible = false;
xrTableRow3.Visible = false;
xrTableCell25.Text = "456";
}
else
{
xrTableCell25.Visible = true;
xrTableRow3.Visible = true;
xrTableCell25.Text = "123";
}
}

change the Text of Button

I have a Button in datagridview and its text is Start so when I Click on it the text now should be Stop and when I click again the text should be Start.
So i have written code but its didnt work for me
private void dgvCampaign_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is Button)
{
Button btn = e.Control as Button;
if(btn.Text=="Start")
btn.Text = "Stop";
else
btn.Text = "Start";
}
}
try to use CellContentClick event
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 2)
{
if (dataGridView2[e.ColumnIndex, e.RowIndex].EditedFormattedValue.ToString().Length > 0)
{
if (dataGridView2[e.ColumnIndex, e.RowIndex].EditedFormattedValue.ToString() == "Start")
{
dataGridView2[e.ColumnIndex, e.RowIndex].Value = "Stop";
}
else
{
dataGridView2[e.ColumnIndex, e.RowIndex].Value = "Start";
}
}
else
dataGridView2[e.ColumnIndex, e.RowIndex].Value = "Start";
}
}

Collecting data from People Picker

I want to Collect the usernames added in the PeoplePicker and display them in the textbox on the click of "Add" button for a custom aspx page.
I tried many codes but its not working.
Here is my code:
protected void btnpicker_Click(object sender, EventArgs e)
{
for (int i = 0; i < userPicker.ResolvedEntities.Count; i++)
{
PickerEntity picker = (PickerEntity)userPicker.ResolvedEntities[i];
Hashtable hstEntityData = picker.EntityData;
string accountName = Convert.ToString(hstEntityData["AccountName"]);
txtPicker.Text = "Count" + hstEntityData.Count.ToString();
txtPicker.TextMode = TextBoxMode.MultiLine;
}
}
Help Highly Appreciated.
Try the following code.
protected void btnpicker_Click(object sender, EventArgs e)
{
for (int i = 0; i < userPicker.ResolvedEntities.Count; i++)
{
PickerEntity picker = (PickerEntity)userPicker.ResolvedEntities[i];
yourTextBox.Text = "Count: " + new SPFieldUserValue(yourSPWebObject, Convert.ToInt32(picker.EntityData["SPUserID"]), picker.Key).User.Name;
}
}
This code will give all name of the users in your textbox.

Resources