Hi
Here is a sample of my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace AutomaticStage
{
public partial class AutomaticVar : Form
{
public AutomaticVar()
{
DataTable trueFalse = new DataTable();
trueFalse.Columns.Add("DisplayMem",
System.Type.GetType("System.String"));
trueFalse.Columns.Add("ValueMem",
System.Type.GetType("System.Boolean"));
DataRow row = trueFalse.NewRow();
row[0] = "True";
row[1] = true;
trueFalse.Rows.Add(row);
row = trueFalse.NewRow();
row[0] = "False";
row[1] = false;
trueFalse.Rows.Add(row);
InitializeComponent();
stageDetailsBindingSource.Add(new StageDetails(true, "A EQ
InvoiceNumber AND InvoiceDate GT today", 1));
stageDetailsBindingSource.Add(new StageDetails(false, "C=D", 2));
stageDetailsBindingSource.Add(new StageDetails(true, "E=F", 3));
//stageDetailsBindingSource.Add(new StageDetails(false, "C=D",
2));
//stageDetailsBindingSource.Add(new StageDetails(true, "E=F", 3));
//stageDetailsBindingSource.Add(new StageDetails(false, "C=D",
2));
//stageDetailsBindingSource.Add(new StageDetails(true, "E=F", 3));
//stageDetailsBindingSource.Add(new StageDetails(false, "C=D",
2));
//stageDetailsBindingSource.Add(new StageDetails(true, "E=F", 3));
//stageDetailsBindingSource.Add(new StageDetails(false, "C=D",
2));
//stageDetailsBindingSource.Add(new StageDetails(true, "E=F", 3));
stageDetailsBindingSource.AllowNew = true;
conditionComboboxColumn.ValueMember = "ValueMem";
conditionComboboxColumn.DisplayMember = "DisplayMem";
conditionComboboxColumn.DataSource = trueFalse;
this.dataGridView1.CellDoubleClick += new
DataGridViewCellEventHandler(dataGridView1_CellDoubleClick);
this.dataGridView1.CellContentClick += new
DataGridViewCellEventHandler(dataGridView1_CellContentClick);
this.dataGridView1.MouseMove +=new
MouseEventHandler(dataGridView1_MouseMove);
this.dataGridView1.MouseDown +=new
MouseEventHandler(dataGridView1_MouseDown);
this.dataGridView1.DragDrop +=new
DragEventHandler(dataGridView1_DragDrop);
this.dataGridView1.DragOver +=new
DragEventHandler(dataGridView1_DragOver);
dataGridViewElse.Rows.Add("Else", "");
//dataGridViewElse.Rows.Add("hidden", "");
//dataGridViewElse.Rows[1].Selected = true;
}
void dataGridView1_CellDoubleClick(object sender,
DataGridViewCellEventArgs e)
{
Form frm = new ExpressionTiff(); // simulate expresson form
frm.ShowDialog();
int a = 0;
stageDetailsBindingSource.ResetBindings(false);
StageDetails stageDetail =
(StageDetails)this.dataGridView1.Rows[this.dataGridView1.CurrentCell.RowIndex].DataBoundItem;
stageDetail.Condition = true;
stageDetail.ExpressionText = "AAAAAAAAAAAAAAAAAAAAAAAAAAAA";//
stageDetail.ExpressionIcode = 4;
//stageDetailsBindingSource.SuspendBinding();
//stageDetailsBindingSource.Add(new StageDetails(true, "G=H", 4));
//stageDetailsBindingSource.ResumeBinding();
//StageDetails[] details = stageDetailsBindingSource.DataSource
as StageDetails[];
//StageDetails[] details =
(StageDetails[])stageDetailsBindingSource.DataSource;
}
void dataGridView1_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
if (IsANonHeaderButtonCell(e))
{
StageDetails stageDetail =
(StageDetails)this.dataGridView1.Rows[this.dataGridView1.CurrentCell.RowIndex].DataBoundItem;
int expressionIcode = stageDetail.ExpressionIcode;
MessageBox.Show("Expression ID = " +
expressionIcode.ToString());
}
if (IsANonHeaderLinkCell(e))
{
StageDetails stageDetail =
(StageDetails)this.dataGridView1.Rows[this.dataGridView1.CurrentCell.RowIndex].DataBoundItem;
Form frm = new ExpressionTiff();
frm.ShowDialog();
}
}
private bool IsANonHeaderButtonCell(DataGridViewCellEventArgs
cellEvent)
{
if (this.dataGridView1.Columns[cellEvent.ColumnIndex] is
DataGridViewButtonColumn &&
cellEvent.RowIndex != -1)
{ return true; }
else { return (false); }
}
private bool IsANonHeaderLinkCell(DataGridViewCellEventArgs cellEvent)
{
if (this.dataGridView1.Columns[cellEvent.ColumnIndex] is
DataGridViewLinkColumn && cellEvent.RowIndex != -1)
{
return true;
}
else
{
return false;
}
}
//void dataGridView1_DataError(object sender,
DataGridViewDataErrorEventArgs e)
//{
// // throw new Exception("The method or operation is not
implemented.");
//}
//////////////////////////
private Rectangle dragBoxFromMouseDown;
private int rowIndexFromMouseDown;
private int rowIndexOfItemUnderMouseToDrop;
private void dataGridView1_MouseMove(object sender, MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
{
// If the mouse moves outside the rectangle, start the drag.
if (dragBoxFromMouseDown != Rectangle.Empty &&
!dragBoxFromMouseDown.Contains(e.X, e.Y))
{
// Proceed with the drag and drop, passing in the list
item.
DragDropEffects dropEffect = dataGridView1.DoDragDrop(
dataGridView1.Rows[rowIndexFromMouseDown],
DragDropEffects.Move);
}
}
}
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
// Get the index of the item the mouse is below.
rowIndexFromMouseDown = dataGridView1.HitTest(e.X, e.Y).RowIndex;
if (rowIndexFromMouseDown != -1)
{
// Remember the point where the mouse down occurred.
// The DragSize indicates the size that the mouse can move
// before a drag event should be started.
Size dragSize = SystemInformation.DragSize;
// Create a rectangle using the DragSize, with the mouse
position being
// at the center of the rectangle.
dragBoxFromMouseDown = new Rectangle(new Point(e.X -
(dragSize.Width / 2),
e.Y - (dragSize.Height / 2)),
dragSize);
}
else
// Reset the rectangle if the mouse is not over an item in
the ListBox.
dragBoxFromMouseDown = Rectangle.Empty;
}
private void dataGridView1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void dataGridView1_DragDrop(object sender, DragEventArgs e)
{
// The mouse locations are relative to the screen, so they must
be
// converted to client coordinates.
Point clientPoint = dataGridView1.PointToClient(new Point(e.X,
e.Y));
// Get the row index of the item the mouse is below.
rowIndexOfItemUnderMouseToDrop =
dataGridView1.HitTest(clientPoint.X, clientPoint.Y).RowIndex;
// If the drag operation was a move then remove and insert the
row.
if (e.Effect == DragDropEffects.Move)
{
DataGridViewRow rowToMove = e.Data.GetData(
typeof(DataGridViewRow)) as DataGridViewRow;
dataGridView1.Rows.RemoveAt(rowIndexFromMouseDown);
dataGridView1.Rows.Insert(rowIndexOfItemUnderMouseToDrop,
rowToMove);
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}