Ill post some, but it is a rather large project.
I Use this method the remove the old event and add the new event for my ComboBoxcolumns, for some reason the portion of code in the comments causes the program to crash.
Code:
private void DataEditingControlShowingEvent(object sender, DataGridViewEditingControlShowingEventArgs e)
{
DataGridView grid = sender as DataGridView;
if (grid != null)
{
DataGridViewComboBoxEditingControl cbx = e.Control as DataGridViewComboBoxEditingControl;
if (cbx != null)
{
if (grid.CurrentCell.ColumnIndex == grid.Columns["Pattern"].Index)
{
cbx.SelectedValueChanged -= this.PatternBoxSelectedValueChangedEvent;
cbx.SelectedValueChanged += this.PatternBoxSelectedValueChangedEvent;
}//new added this portion for editable ID tags
/*if (grid.CurrentCell.ColumnIndex == grid.Columns["ID"].Index)
{
cbx.SelectedValueChanged -= this.IdBoxSelectedValueChangedEvent;
cbx.SelectedValueChanged += this.IdBoxSelectedValueChangedEvent;
}*/
}
}
}
this is the event for when the pattern gets changed, this works fine
Code:
private void PatternBoxSelectedValueChangedEvent(object sender, EventArgs e)
{
// this event causes dynamic change for the calculated values when the Pattern
// drop down changes selection.
ComboBox cbx = sender as ComboBox;
if ((cbx != null) && (cbx.SelectedIndex > -1))
{
int ballqty;
PatternXML pat = cbx.SelectedItem as PatternXML;
//MessageBox.Show("pattern item: " + pat.ToString());
if ((int.TryParse(datagrid.CurrentRow.Cells["BallQty"].Value.ToString(), out ballqty)) &&
(pat != null) && (datagrid.CurrentRow.Cells["ID"].Value.ToString() != pat.ID.ToString()))
{
datagrid.CurrentRow.Cells["ID"].Value = pat.ID;
datagrid.CurrentRow.Cells["Frequency"].Value = PaytableCalculator.CalcFrequency(pat, ballqty);
}
}
}
Here is the code for the changing of the Id box.
Code:
private void IdBoxSelectedValueChangedEvent(object sender, EventArgs e)
{
ComboBox cbx = sender as ComboBox;
int ballqty;
if ((cbx != null) && (cbx.SelectedIndex > -1))
{
// MessageBox.Show("id item: " + cbx.SelectedValue);
//grab the id from the combobox
int id = (int)(cbx.SelectedItem);
//get the pattern object
PatternXML pat = GetPatternById(id);
//copy the pattern into the datagrid cell if it isnt already there
if (((int.TryParse(datagrid.CurrentRow.Cells["BallQty"].Value.ToString(), out ballqty)) &&
(pat != null) && (datagrid.CurrentRow.Cells["Pattern"].Value != pat.Value)))
{
datagrid.CurrentRow.Cells["Pattern"].Value = pat.Value;
datagrid.CurrentRow.Cells["Frequency"].Value = PaytableCalculator.CalcFrequency(pat, ballqty);
}
}
}
And attached is what the screen looks like.
any help would be awesome.
Hunter