Toolstripmenuitem not running method C# - c#

I have a method that foreaches a row within a datagridview and starts a process. However, when I click the toolstripmenuitem to execute the method it does not work. Any suggestions?
This is the toolstripmenuitem ^
private void sIGNATUREToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (Properties.Settings.Default.ManageContactsView == "STACKED")
{
ViewSignature(AllContacts);
}
else if (Properties.Settings.Default.ManageContactsView == "LISTED")
{
ViewSignature(AllContactsLISTED);
}
else
{
ViewSignature(AllContactsFULL);
}
}
This is the code that is placed in the menu items click property ^
void ViewSignature(DataGridView AllContacts)
{
foreach (DataGridViewRow row1 in AllContacts.Rows)
{
try
{
if (Convert.ToBoolean(row1.Cells[18].Value))
{
Process.Start(Properties.Settings.Default.ReferencePoint + #"/Contacts/Contact_" + row1.Cells[0].Value.ToString() + #"/Signature.jpg");
}
}
catch
{
//Error message if the system cannot remove the contact from the database.
MessageBox.Show("Sorry, something went wrong. Please try again later.\n\nERROR CODE: BINSPIRE1009", "BLUEBERRY INSPIRE 2022", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
This is the method I am trying to execute which fetches a column and row value from the datagridview and starts a process.

Related

RowUniqueID in filtered row

could somebody help me in C# programing in an web application. Namely, how can we find out RecordUniqueId of the filtered row....in order to further edit (i.e., set values in some other columns in the same row), based on RecordUniqueId value? Or, is it possible to, upon clicking on enter button in order to search for certain row, to immediately have some actions performed on the values in some other columns of filtered row? Let me say in other words, to have some kind of automation of editing values in some other columns of the filtered row?
Thanks in advance
public class PartyVuk2010GENTableControlRow : BasePartyVuk2010GENTableControlRow
{
}
public class PartyVuk2010GENTableControl : BasePartyVuk2010GENTableControl
{
public override void MarkDiscontinued_Click(object sender, ImageClickEventArgs args)
{
try {
DbUtils.StartTransaction();
foreach (PartyVuk2010GENTableControlRow rc in this.GetSelectedRecordControls()) {
PartyVuk2010GENRecord rec;
rec = PartyVuk2010GENTable.GetRecord(rc.RecordUniqueId, true);
if (rec != null) {
rec.Discontinued = true;
rec.Test = "10";
rec.BallotOrder = PartyVuk2010GENTable.Instance.GetLargest()+1;
rec.Save();
}
}
DbUtils.CommitTransaction();
}
catch (Exception ex) {
BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
}
finally {
DbUtils.EndTransaction();
}
this.DataChanged = true;
}

need to tick the checkbox in Datagridview C#

I need to tick the checkbox in datagridview.in my case, I wanna do validation when the user going to untick the checkbox,
I wanna tick the checkbox after message will show
private void dgvBookingType_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
DataGridViewRow dgvRow = dgvBookingType.CurrentRow;
if (dgvRow.Cells[0].Value.ToString() == "True")
{
dgvRow.Cells[0].Value = true;
if (_dsEvent.Tables.Contains("PackageBookingType"))
{
if (_dsEvent.Tables["PackageBookingType"] != null)
{
DataRow[] selectedRow = _dsEvent.Tables["PackageBookingType"].Select("BookingTypeId=" + dgvRow.Cells[1].Value + " ");
if (selectedRow.Length > 0)
oUtilOptimised.ShowGenericUIValidation("There are packages that belong to the selected booking type added to the event. Remove the packages in order to disable the selected booking type", MessageBoxButtons.OK, MessageBoxDefaultButton.Button1, this, true);
}
}
}
}
please help me

Datagridview How to skip blank rows deleted?

datagridview How to skip blank rows deleted?
this is the following error :
Deleted row information cannot be accessed through the row
this is my code: http://pasted.co/bcb3fb31
You have to implement SQL DataTable event handler like the one shown below:
YourDataTable.RowDeleted += new DataRowChangeEventHandler(dataTable_RowChanged);
private void dataTable_RowChanged(object sender, DataRowChangeEventArgs e)
{
DataRow _dr = e.Row as DataRow;
try
{
if (e.Row.RowState == DataRowState.Deleted)
{
// YOUR CODE
}
if (e.Row.RowState == DataRowState.Added) { //OPTIONAL }
if (e.Row.RowState == DataRowState.Modified) { //OPTIONAL}
}
catch (Exception ex) { }
finally { _dr = null; }
}
Hope this may help. Best regards,

How to compare new and previous value in combobox?

i have datagridview and column in it,and type is combobox.Combobox value's are used from sql data base.In combobox "Status" i have 5 different item value's.What i want is that when i change item value from combobox and press "save" button ,i want to check which value was before this one(before save) and say:
private void m02BindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
try
{
if (StatusTextBox.Text == "3" && // + want to ask here if previous statusTextBox.text was "1" then to execute lines down if not goes to 'else')
{
DialogResult mbox = MessageBox.Show("do you want to save today's date and time?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
datumOtvaranjaDateTimePicker.Focus();
if (mbox == DialogResult.Yes)
{
datumOtvaranjaDateTimePicker.Value = DateTime.Now;
}
Save();
Refresh();
}
else
{
MessageBox.Show("you cant do that!!!" + Environment.NewLine + "Check what you typed and try again", "Upozorenje", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Refresh();
}
}
catch (Exception)
{
}
}
Look at this other answer
You can handle the ComboBox.Enter event. Then save off the
SelectedItem or SelectedValue to a member variable
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
comboBox1.Enter += comboBox1_Enter;
}
private void comboBox1_Enter(object sender, EventArgs e)
{
m_cb1PrevVal = comboBox1.SelectedValue;
}
private void RestoreOldValue()
{
comboBox1.SelectedValue = m_cb1PrevVal;
}
}

Using cellcontentclick event in a c# program that activates a link

I have a program that uses a datagridview with 7 columns in it. One of the columns is a hyperlink that will load a file from a specified location. I use a 'cellcontentclick' event to open the file. My problem is, when I click any of the other cells in the row, it will still execute the cellcontentclick. How do I make it so only when that specific column will execute when clicked?
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
try
{
string sourcePath = #"SPECIFIED PATH";
Process.Start(sourcePath + dataGridView1.Rows[e.RowIndex].Cells[5].Value);
}
catch (SqlException e)
{
MessageBox.Show("Error occured: " + e);
}
}
Check inside event handler only for column you are looking for.
One of the parameters (e?) has column info.
Got it! I just needed to enter the if statement and specify the column. Thanks, evgenyl.
if (e.ColumnIndex == 5 && e.RowIndex >= 0)
{
try
{
string sourcePath = #"PATH";
Process.Start(sourcePath + dataGridView1.Rows[e.RowIndex].Cells[5].Value);
}
catch (SqlException a)
{
MessageBox.Show("Error occured: " + a);
}
}

Categories