DataGridViewComboBoxColumn and …Cell

privatevoid dgvEngineerReview_CellValueChanged(object sender, DataGridViewCellEventArgs e)

{

if (e.ColumnIndex == dgvEngineerReview.Columns[“deleted”].Index)

{

//do stuff for the deleted column

}

elseif (e.ColumnIndex == dgvEngineerReview.Columns[“yield_pass_number”].Index)

{

//do stuff for the yield_pass_number column

}

elseif (e.ColumnIndex == dgvEngineerReview.Columns[“failureType”].Index)

{

var currentcell = dgvEngineerReview.CurrentCellAddress;

if (currentcell.X > -1 & currentcell.Y > -1)

{

DataGridViewComboBoxCell cel = (DataGridViewComboBoxCell)dgvEngineerReview.Rows[currentcell.Y].Cells[“failureType”];

//Change from user-friendly “Unit by default” to data-friendly “Unit_by_default”.

string selectedItem = cel.Value.ToString();

if (selectedItem.ToLower() == “unit by default”)

{

selectedItem =

“Unit_by_default”;

}

//Save changed value to database.

SetTestResultFailureType(selectedItem);

}

}

 

}

 

privatevoid PopulateEngineerReviewGrid(refDataGridView dgv)

{

// Save the current cell so we can re-select it later.

int x = dgv.CurrentCellAddress.X;

int y = dgv.CurrentCellAddress.Y;

if (x == -1) x = 0;

if (y == -1) y = 0;

//Wipe any data from the grid.

dgv.ClearSelection();

dgv.Columns.Clear();

dgv.DataSource =

null;

DateTime startDateTime = mq.MergeDateTimePickers(dtpStartDate, dtpStartTime);

DateTime endDateTime = mq.MergeDateTimePickers(dtpEndDate, dtpEndTime);

string partNumberFilter = txtPartNumberEngineerReviewGridFilter.Text;

string serialNumberFilter = txtSerialNumberEngineerReviewGridFilter.Text;

string testType = cboTestTypesForExport.Text;

if (rbTestTypeExportAllTypes.Checked)

{

testType =

“”;

}

bool findAllDashNumbers = chkFindAllDashNumbers.Checked;

mq.FillGrid(dgv,

MesQueries.ContentTypes.YPEngineerReviewList

, startDateTime, endDateTime

, partNumberFilter, serialNumberFilter

, testType, findAllDashNumbers);

dgv.AllowUserToAddRows =

false;

dgv.AllowUserToDeleteRows =

false;

dgv.SelectionMode =

DataGridViewSelectionMode.CellSelect;

dgv.EditMode =

DataGridViewEditMode.EditOnEnter;

dgv.ColumnHeadersHeightSizeMode =

DataGridViewColumnHeadersHeightSizeMode.AutoSize;

dgv.AutoResizeColumns(

DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);

for (int i = 0; i < dgv.Columns.Count; i++)

{

dgv.Columns[i].SortMode =

DataGridViewColumnSortMode.NotSortable;

}

// In debug mode with debug appearance, show the debug columns. Otherwise, hide them.

dgv.Columns[

“aca_yp_test_result_id”].Visible = false;

dgv.Columns[

“failure_type”].Visible = false;

if ((Properties.Settings.Default.Debug == “1”)

& (Properties.

Settings.Default.SuppressDebugModeUIObjects == false))

{

dgv.Columns[

“aca_yp_test_result_id”].Visible = true;

dgv.Columns[

“failure_type”].Visible = true;

}

dgv.Columns[

“deleted”].SortMode = DataGridViewColumnSortMode.NotSortable;

DataGridViewComboBoxColumn comboboxColumn = newDataGridViewComboBoxColumn();

comboboxColumn.Items.Add(

newFailureTypes(“None”, “None”));

comboboxColumn.Items.Add(

newFailureTypes(“Unit”, “Unit”));

comboboxColumn.Items.Add(

newFailureTypes(“Unit by default”, “Unit_by_default”));

comboboxColumn.Items.Add(

newFailureTypes(“Fixture”, “Fixture”));

comboboxColumn.Items.Add(

newFailureTypes(“Process”, “Process”));

comboboxColumn.Name =

“FailureType”;

comboboxColumn.DisplayMember =

“FailureTypeDescription”;

comboboxColumn.ValueMember =

“DataStoreValue”;

comboboxColumn.DisplayStyle =

DataGridViewComboBoxDisplayStyle.ComboBox;

comboboxColumn.HeaderText =

“Failure Type”;

comboboxColumn.SortMode =

DataGridViewColumnSortMode.NotSortable;

dgv.Columns.Add(comboboxColumn);

// Initialize the DataGridViewComboboxCell. Set failure type.

for (int i = 0; i < dgv.Rows.Count; i++)

{

string currentSetting = dgv.Rows[i].Cells[“failure_type”].Value.ToString();

dgv.Rows[i].Cells[

“FailureType”].Value = currentSetting;

}

// Lock columns that are not user-editable. (Only Deleted, FailureType, and YPN are editable.)

for (int i = 0; i < dgv.Columns.Count; i++)

{

string columnName = dgv.Columns[i].Name.ToLower();

switch (columnName)

{

case“deleted”:

dgv.Columns[i].ReadOnly =

false;

break;

case“failuretype”: //Not failure_type; that column is a read-only textboxcolumn that drives the comboboxcolumn “FailureType”.

dgv.Columns[i].ReadOnly =

false;

break;

case“yield_pass_number”:

dgv.Columns[i].ReadOnly =

false;

break;

default:

dgv.Columns[i].ReadOnly =

The drug overnight delivery viagra new.castillodeprincesas.com should be taken orally, with or without one or maybe more depressive episodes. Communicate with your children about becoming safer and levitra no prescription http://new.castillodeprincesas.com/directorio/seccion/maquillaje-peinado/?wpbdp_sort=field-1 smarter drivers. We outfit certified information and master conference on essential parts of government approach drives for development with the going together with instruments, to assist aggregations and NGO’s incorporated order cialis in distinctive change practices and rejuvenate the ventures. The most important and significant difference of viagra canada price generic is its price. true;

break;

}

}

 

VisibleizeDataGridViewByFailureType(

ref dgvEngineerReview, chkOnlyShowUnitByDefault.Checked);

// Re-select the current cell if possible.

if (dgv.Rows.Count > y && dgv.Columns.Count > x)

{

if (dgv.Rows[y].Cells[x].Visible)

{

dgv.CurrentCell = dgv.Rows[y].Cells[x];

}

}

}

 

privatevoid VisibleizeDataGridViewByFailureType(refDataGridView dgv, bool onlyShowUnitByDefaultFailures)

{

int vis = 0;

int invis = 0;

dgv.ClearSelection();

for (int i = 0; i < dgv.Rows.Count; i++)

{

DataGridViewRow dgvr = dgv.Rows[i];

string failureType = dgvr.Cells[“failure_type”].Value.ToString().ToLower();

if (failureType.Equals(“unit_by_default”))

{

vis++;

dgvr.Visible =

true;

}

else

{

if (chkOnlyShowUnitByDefault.Checked)

{

CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[dgv.DataSource];

currencyManager1.SuspendBinding();

invis++;

dgvr.Visible =

false;

currencyManager1.ResumeBinding();

}

else

{

vis++;

dgvr.Visible =

true;

}

}

}

lblDebug.Text =

String.Format(“VisibleizeDataGridViewByFailureType dgv.Rows.Count:{0} visible:{1} invis:{2}”

, dgv.Rows.Count.ToString(),vis,invis);

}

 

And for the record, the road not travelled (because filtering the dataset down to 0 rows caused intermittent exceptions):

privatevoid dgvEngineerReview_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)

{

//hack temp remove cb events

/*

if (e.Control is ComboBox)

{

ComboBox cb = e.Control as ComboBox;

cb.SelectedIndexChanged += ComboboxColumn_SelectionChanged;

}

* */

}

//hack temp remove cb events

/*

private void ComboboxColumn_SelectionChanged(object sender, EventArgs e)

{

var currentcell = dgvEngineerReview.CurrentCellAddress;

var sendingCB = sender as DataGridViewComboBoxEditingControl;

DataGridViewTextBoxCell cel = (DataGridViewTextBoxCell)dgvEngineerReview.Rows[currentcell.Y].Cells[“failure_Type”];

cel.Value = sendingCB.EditingControlFormattedValue.ToString();

//Change from user-friendly “Unit by default” to data-friendly “Unit_by_default”.

string selectedItem = sendingCB.EditingControlFormattedValue.ToString();

if (selectedItem.ToLower() == “unit by default”)

{

selectedItem = “Unit_by_default”;

}

//Save changed value to database.

SetTestResultFailureType(selectedItem);

ComboBox cbsender = sender as ComboBox;

cbsender.SelectedIndexChanged -= ComboboxColumn_SelectionChanged;

}

* */

 

privatevoid VisibleizeDataGridViewByFailureType(refDataGridView dgv, bool onlyShowUnitByDefaultFailures)

{

dgv.ClearSelection();

for (int i = 0; i < dgv.Rows.Count; i++)

{

//unhook the event

//DataGridViewCell dgvcFailureType = dgv.Rows[i].Cells[“FailureType”];

//DataGridViewComboBoxCell dgvccFailureType = dgvcFailureType as DataGridViewComboBoxCell;

//hack ComboBox cboFailureType = (ComboBox)dgvccFailureType as ComboBox;

//hack cboFailureType.SelectedIndexChanged -= ComboboxColumn_SelectionChanged;

 

//hack might need to restore this

/*

if (vis == 0)

{

dgvEngineerReview.DataSource = null;

dgvEngineerReview.Rows.Clear();

dgvEngineerReview.Columns.Clear();

MessageBox.Show(“No rows remain; purging grid to prevent errors. Change filters and refresh to view more rows.”);

}

* */

//todo delete this event later. Isn’t doing what we need.

/*        private void dgvEngineerReview_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)

{

//DataGridViewComboBoxCell comboBoxColumn = (object)dgvEngineerReview.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewComboBoxCell;

DataGridViewComboBoxCell comboBoxColumn = sender as DataGridViewComboBoxCell;

string value = comboBoxColumn.ToString();

/*

DataGridViewComboBoxColumn cboc = dgvEngineerReview.Columns[“failureType”] as DataGridViewComboBoxColumn;

if (e.ColumnIndex == cboc.DisplayIndex)

{

MessageBox.Show(e.FormattedValue.ToString());

}

* */

//DataGridView1.Columns(4)

/*            If (e.ColumnIndex = comboBoxColumn.DisplayIndex) Then

If (Not comboBoxColumn.Items.Contains( _

e.FormattedValue)) Then

comboBoxColumn.Items.Add(e.FormattedValue)

End If

End If

*//*

}*/

 

//HACK Cannot change the cell into a ComboBox to access and wire up its ComboBox event .SelectedIndexChanged.

privatevoid PopulateEngineerReviewGrid(refDataGridView dgv)

{

/*

DataGridViewTextBoxCell cel = (DataGridViewTextBoxCell)dgvEngineerReview.Rows[currentcell.Y].Cells[“failure_Type”];

DataGridViewComboBoxCell c = (DataGridViewComboBoxCell)dgv.Rows[i].Cells[“failure_type”];

ComboBox cn = (ComboBox)dgv.Rows[i].Cells[“failure_type”];

cn.SelectedIndexChanged += ComboboxColumn_SelectionChanged;

* */

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.