ListView1_ItemChecked event in c# 2008 - c#

How to call the ListView1_ItemChecked event in the buttonclick event?

Assuming you are trying to simulate the checked event.
void Button1_Click(object sender, EventArgs args)
{
ListViewItem item = // get the item you want
ItemCheckedEventArgs checkedArgs = new ItemCheckedEventArgs(item);
ListView1.ItemChecked(sender, checkedArgs);
}

Related

Raise an Event Except when something happpen

Scenario: Only If the user follow the path Click on ListView > Click on Button the Button1 do something.
In other word I want to check in Button1_Click(object sender, EventArgs e) if the previous focus was on ListView.
So I tried this:
private void ListView_Test_Leave(object sender, EventArgs e)
{
_focusedControl = null;
}
I want raise previous event except when this event is raised:
private void Button1_Click(object sender, EventArgs e)
{
if(_focusedControl == listView_Test)
{
// ...
}
}
Edit: I have a variable that holds a reference to the currently focused control:
private Control _focusedControl;
and I update it in this way:
private void ListView_Test_GotFocus(object sender, EventArgs e)
{
_focusedControl = (Control)sender;
}
If the user follow the path Click on ListView > Click on Button I want raise only the Button1_Click event, in all other case I want normal raise.
You could use a helper variable.
bool wasRaised=false;
private void Button1_Click(object sender, EventArgs e) { wasRaised=true;}
Then you can check that variable in your event, and only run if it is false.

Fire Menu Strip Item Click Event Dynamically in C# Windows Form

I have already added a menu strip controller and added click events for those menu items.
Ex:
private void mnuaddTestingBuyersForFigures_Click(object sender, EventArgs e)
{
frmAddTestingBuyersForFigure obj = new frmAddTestingBuyersForFigure();
objUserManagerBll.SetAccess(obj, User.UserID);
IsAlreadyLoded(obj);
}
private void mnuOperatorIncentive_Click(object sender, EventArgs e)
{
frmOperatorIncentive obj = new frmOperatorIncentive();
objUserManagerBll.SetAccess(obj, User.UserID);
IsAlreadyLoded(obj);
}
private void mnuSetUpIncentiveMonthProcess_Click(object sender, EventArgs e)
{
frmSetUpWeeksForIncentiveMonth obj = new frmSetUpWeeksForIncentiveMonth();
objUserManagerBll.SetAccess(obj, User.UserID);
IsAlreadyLoded(obj);
}
Here I want fire above click event from another event. I just want to pass the menu strip name as parameter to the method and fire corresponding event of it.
Ex :
ShowMe("mnuSetUpIncentiveMonthProcess");
//Out put open the frmSetUpWeeksForIncentiveMonth form
ShowMe("mnuOperatorIncentive");
//Out put open the frmOperatorIncentive form
Without using conditional statements
You can find the control by its name and then call its PerformClick() method:
private void ShowMe(string name)
{
var item = (MenuStripItem)this.Controls[name];
item.PerformClick();
}

Sometime Except Combo Box's SelectedIndexChanged

I have one Combo box and it has SelectedIndexChanged Event but i want Ignore that event in some case how can i achieve that functionality.
describe code is below
private void Form1_Load(object sender, EventArgs e)
{
List<string> lstString = new List<string>();
lstString.Add("One");
lstString.Add("Two");
lstString.Add("Three");
foreach (string str in lstString)
cBox.Items.Add(str);
//Here I want Ignore cbox_SelectedIndexChanged Event
cBox.SelectedIndex = 0;
}
private void cBox_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("Your Selected Item is :- " + cBox.SelectedItem.ToString());
}
You can choose either of the 2 approaches.
Have a bool flag which will be set for those conditions when you want to ignore the event handler from running. And use that flag inside your SelectedIndexChanged method
Subscribe to the event only after you have set cBox.SelectedIndex=0 if that is the only case.
Instead of subscribing the event within the designer (I expect you to do this at the moment) you can subscribe to the event in code after the initialization is done.
private void Form1_Load(object sender, EventArgs e)
{
// Init stuff
cBox.SelectedIndex = 0;
// Event subscription
cBox.SelectedIndexChanged += cBox_SelectedIndexChanged;
}
private void cBox_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("Your Selected Item is :- " + cBox.SelectedItem.ToString());
}

cannot find where event is being raised from

I Create a function NewLoad() and call it in butto1_click.
And i have event listBox1_SelectedIndexChanged which called itself during operation function "NewLoad"
private void button1_Click(object sender, EventArgs e)
{
NewLoad();
}
private void NewLoad()
{
String text = textBox1.Text.Trim();
textBox1.Text = text;
oleDbSelectCommand1.Parameters[0].Value = text;
dataSet11.Clear(); <<<--- call listbox1_SelectedIndexChanged
oleDbDataAdapter1.Fill(dataSet11);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
dataSet21.Clear();
}
why this happens and how i can to avoid it?
My psychic debugging skills tell me that the listbox is databound to the dataset.
When you clear your dataset, the listbox is emptied, and the selection changes.
This raises the relevant event.
If you have something selected in list box 1, when you clear it, the selected index will change, thus raising selection changed event.

Action immediately after selecting Item

I have this code:
private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedItem.ToString() == "blahblah")
{
processing ps = new processing();
pictureBox1.Image = ps.blahblah(bmp);
}
else
{...
}
}
So the action of the ComboBox is done by clicking on the button1.
It is possible to take action immediately after selecting Item? without button clicking?
Subscribe to the SelectedIndexChanged event
comboBox1.SelectedIndexChanged += OnSelectedIndexChanged;
private void OnSelectedIndexChanged(object sender, EventArgs e) {
// Handle combo box changing
}
Try using this event,
ComboBox1.SelectedIndexChanged
and do
AutoPostBack = "true"
in your mark up if you want to check the selected item immediately after selecting item.

Categories