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";//
"G=H qweqwuieyuiyeqwuyqweu qwkjbcsdjkfhweiug";
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();
}
}
}
Zhi-Xin Ye said:
Hi,
Thank you for using Microsoft Managed Newsgroup Service, it's my pleasure
to work with you on this issue.
As I understand, you have a DataGridView control which is data bound, one
of its columns is a DataGridViewLinkColumn. And you handle the
CellDoubleClick event, in the event handler, you add content for the
current row, and you found if the content in the DataGridViewLinkCell is
long enough to be in the place where the user double clicks, the
CellContentClick event fires as well.
I try to reproduce this problem with the following code, when I double
click on the DataGridViewLinkCell, the CellDoubleClick event fires and
content is added to the cell, but the CellContentClick event does not fire.
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("c1", typeof(int));
dt.Columns.Add("c2");
for (int j = 0; j < 50; j++)
{
dt.Rows.Add(j, "");
}
this.dataGridView1.DataSource = dt;
DataGridViewLinkColumn linkCol = new DataGridViewLinkColumn();
linkCol.DataPropertyName = "c2";
this.dataGridView1.Columns.Add(linkCol);
this.dataGridView1.CellDoubleClick += new
DataGridViewCellEventHandler(dataGridView1_CellDoubleClick);
this.dataGridView1.CellContentClick += new
DataGridViewCellEventHandler(dataGridView1_CellContentClick);
}
void dataGridView1_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
Console.WriteLine("Cell Content");
}
void dataGridView1_CellDoubleClick(object sender,
DataGridViewCellEventArgs e)
{
Console.WriteLine("Cell double");
if (e.ColumnIndex == 2)
{
DataRowView drv =
this.dataGridView1.CurrentRow.DataBoundItem as DataRowView;
drv["c2"] =
"asccccccccccccccccccccccccccccccccccccccccccccc";
}
}
If I misunderstand you, please let me know. I look forward to your reply.
Best Regards,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.