18 个解决方案
#1
自己顶一下,高手快来帮帮我吧!
#2
高手???????????????
#3
是不是类似Textbox的_TextChanged事件?没有现成的,要自己写的.
#4
能不能告诉我思路了
#5
帮顶一个!关注ing...学习....
#6
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
在InitializeComponent()中增加如下代码以订阅单元格值改变的方法
this.dataGridView1.CellValueChanged+=new System.Windows.Forms.DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
再在.cs文件中增加dataGridView1_CellValueChanged方法代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
在InitializeComponent()中增加如下代码以订阅单元格值改变的方法
this.dataGridView1.CellValueChanged+=new System.Windows.Forms.DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
再在.cs文件中增加dataGridView1_CellValueChanged方法代码
#7
能不能告诉我那事件里怎么写了 ,我是初学者,很多东西不懂,谢谢!!!
#8
自己顶一下
#9
在datagridview的EditingControlShowing事件中写:
if (e.Control is TextBox)
{
TextBox tb = e.Control as TextBox;
tb.KeyPress += new KeyPressEventHandler(tb_KeyPress);
}
void tb_KeyPress(object sender, KeyPressEventArgs e)
{
//写你要做的那个事件
}
if (e.Control is TextBox)
{
TextBox tb = e.Control as TextBox;
tb.KeyPress += new KeyPressEventHandler(tb_KeyPress);
}
void tb_KeyPress(object sender, KeyPressEventArgs e)
{
//写你要做的那个事件
}
#10
在EditingControlShowing事件中要判断:if (this.datagridview.CurrentCell.OwningColumn.Name == "你需要的列名")
#11
确实可以解决我的问题,但是新的问题出现了,这样以来你点击不同的三个单元格时就会触发三次,如果我点击更多的单元格,就会触发更多次,请问,这个该如何解决了,
#12
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DataGridViewChange
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.dataGridView1.CellValueChanged += new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
}
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=(local);integrated security=SSPI;database=BuildRoom");
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter mydp = new SqlDataAdapter("Select * from Room", conn);
mydp.Fill(ds, "Room");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Room";
conn.Close ();
}
void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//这里输入你要触发的事件
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DataGridViewChange
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.dataGridView1.CellValueChanged += new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
}
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=(local);integrated security=SSPI;database=BuildRoom");
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter mydp = new SqlDataAdapter("Select * from Room", conn);
mydp.Fill(ds, "Room");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Room";
conn.Close ();
}
void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//这里输入你要触发的事件
}
}
}
#13
大概写了一个,运行可以的.
public class MyDataGridViewTextBoxCell : DataGridViewTextBoxCell
{
public MyDataGridViewTextBoxCell()
: base()
{
}
private DataGridViewTextBoxEditingControl dgvtbec;
private DataGridViewColumn dgvc;
private MyDataGridViewColumn mdgvc;
public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
dgvtbec = DataGridView.EditingControl as DataGridViewTextBoxEditingControl;
dgvc = this.OwningColumn;
if (dgvc is MyDataGridViewColumn)
{
mdgvc = dgvc as MyDataGridViewColumn;
dgvtbec.TextChanged += new EventHandler(dgvtbec_TextChanged);
}
}
void dgvtbec_TextChanged(object sender, EventArgs e)
{
mdgvc.DataGridViewColumnTextValue = dgvtbec.Text;
EventCellChangeArgs ee = new EventCellChangeArgs(this.DataGridView.CurrentCell.RowIndex, this.DataGridView.CurrentCell.ColumnIndex, dgvtbec.Text);
mdgvc.MyDataGridViewColumn_DataGridViewTextChanged(sender, ee);
}
}
public class EventCellChangeArgs : EventArgs
{
public int rowIndex;
public int columnIndex;
public string value;
public EventCellChangeArgs(int r, int c, string v)
{
rowIndex = r;
columnIndex = c;
value = v;
}
}
public class MyDataGridViewColumn : DataGridViewColumn
{
public MyDataGridViewColumn()
: base()
{
this.CellTemplate = new MyDataGridViewTextBoxCell();
}
public override DataGridViewCell CellTemplate
{
get
{
return base.CellTemplate;
}
set
{
if (value != null && !value.GetType().IsAssignableFrom(typeof(MyDataGridViewTextBoxCell)))
{
throw new Exception("MyDataGridViewTextBoxCell");
}
base.CellTemplate = value;
}
}
private string m_dataGridViewColumnTextValue = "";
public string DataGridViewColumnTextValue
{
get
{
return m_dataGridViewColumnTextValue;
}
set
{
m_dataGridViewColumnTextValue = value;
}
}
public void MyDataGridViewColumn_DataGridViewTextChanged(object sender, EventCellChangeArgs e)
{
if (DataGridViewTextChanged != null)
{
DataGridViewTextChanged(sender, e);
}
}
public event EventCellChangeEvent DataGridViewTextChanged;
}
public delegate void EventCellChangeEvent(object sender, EventCellChangeArgs e);
private void Form1_Load(object sender, EventArgs e)
{
this.Column1.DataGridViewTextChanged += new BCStainer.Classes.StainerApplication.EventCellChangeEvent(Column1_DataGridViewTextChanged);
}
void Column1_DataGridViewTextChanged(object sender, BCStainer.Classes.StainerApplication.EventCellChangeArgs e)
{
this.label1.Text = e.value;
}
运行时,Column1单元格的会和Textbox_change一样.
#14
#15
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
this.button1.Visible = true;
}
{
this.button1.Visible = true;
}
#16
刚好遇到此问题,进来参考一下
#17
解决问题了?
#18
有用!
#1
自己顶一下,高手快来帮帮我吧!
#2
高手???????????????
#3
是不是类似Textbox的_TextChanged事件?没有现成的,要自己写的.
#4
能不能告诉我思路了
#5
帮顶一个!关注ing...学习....
#6
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
在InitializeComponent()中增加如下代码以订阅单元格值改变的方法
this.dataGridView1.CellValueChanged+=new System.Windows.Forms.DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
再在.cs文件中增加dataGridView1_CellValueChanged方法代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
在InitializeComponent()中增加如下代码以订阅单元格值改变的方法
this.dataGridView1.CellValueChanged+=new System.Windows.Forms.DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
再在.cs文件中增加dataGridView1_CellValueChanged方法代码
#7
能不能告诉我那事件里怎么写了 ,我是初学者,很多东西不懂,谢谢!!!
#8
自己顶一下
#9
在datagridview的EditingControlShowing事件中写:
if (e.Control is TextBox)
{
TextBox tb = e.Control as TextBox;
tb.KeyPress += new KeyPressEventHandler(tb_KeyPress);
}
void tb_KeyPress(object sender, KeyPressEventArgs e)
{
//写你要做的那个事件
}
if (e.Control is TextBox)
{
TextBox tb = e.Control as TextBox;
tb.KeyPress += new KeyPressEventHandler(tb_KeyPress);
}
void tb_KeyPress(object sender, KeyPressEventArgs e)
{
//写你要做的那个事件
}
#10
在EditingControlShowing事件中要判断:if (this.datagridview.CurrentCell.OwningColumn.Name == "你需要的列名")
#11
确实可以解决我的问题,但是新的问题出现了,这样以来你点击不同的三个单元格时就会触发三次,如果我点击更多的单元格,就会触发更多次,请问,这个该如何解决了,
#12
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DataGridViewChange
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.dataGridView1.CellValueChanged += new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
}
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=(local);integrated security=SSPI;database=BuildRoom");
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter mydp = new SqlDataAdapter("Select * from Room", conn);
mydp.Fill(ds, "Room");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Room";
conn.Close ();
}
void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//这里输入你要触发的事件
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DataGridViewChange
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.dataGridView1.CellValueChanged += new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);
}
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=(local);integrated security=SSPI;database=BuildRoom");
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter mydp = new SqlDataAdapter("Select * from Room", conn);
mydp.Fill(ds, "Room");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Room";
conn.Close ();
}
void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//这里输入你要触发的事件
}
}
}
#13
大概写了一个,运行可以的.
public class MyDataGridViewTextBoxCell : DataGridViewTextBoxCell
{
public MyDataGridViewTextBoxCell()
: base()
{
}
private DataGridViewTextBoxEditingControl dgvtbec;
private DataGridViewColumn dgvc;
private MyDataGridViewColumn mdgvc;
public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
dgvtbec = DataGridView.EditingControl as DataGridViewTextBoxEditingControl;
dgvc = this.OwningColumn;
if (dgvc is MyDataGridViewColumn)
{
mdgvc = dgvc as MyDataGridViewColumn;
dgvtbec.TextChanged += new EventHandler(dgvtbec_TextChanged);
}
}
void dgvtbec_TextChanged(object sender, EventArgs e)
{
mdgvc.DataGridViewColumnTextValue = dgvtbec.Text;
EventCellChangeArgs ee = new EventCellChangeArgs(this.DataGridView.CurrentCell.RowIndex, this.DataGridView.CurrentCell.ColumnIndex, dgvtbec.Text);
mdgvc.MyDataGridViewColumn_DataGridViewTextChanged(sender, ee);
}
}
public class EventCellChangeArgs : EventArgs
{
public int rowIndex;
public int columnIndex;
public string value;
public EventCellChangeArgs(int r, int c, string v)
{
rowIndex = r;
columnIndex = c;
value = v;
}
}
public class MyDataGridViewColumn : DataGridViewColumn
{
public MyDataGridViewColumn()
: base()
{
this.CellTemplate = new MyDataGridViewTextBoxCell();
}
public override DataGridViewCell CellTemplate
{
get
{
return base.CellTemplate;
}
set
{
if (value != null && !value.GetType().IsAssignableFrom(typeof(MyDataGridViewTextBoxCell)))
{
throw new Exception("MyDataGridViewTextBoxCell");
}
base.CellTemplate = value;
}
}
private string m_dataGridViewColumnTextValue = "";
public string DataGridViewColumnTextValue
{
get
{
return m_dataGridViewColumnTextValue;
}
set
{
m_dataGridViewColumnTextValue = value;
}
}
public void MyDataGridViewColumn_DataGridViewTextChanged(object sender, EventCellChangeArgs e)
{
if (DataGridViewTextChanged != null)
{
DataGridViewTextChanged(sender, e);
}
}
public event EventCellChangeEvent DataGridViewTextChanged;
}
public delegate void EventCellChangeEvent(object sender, EventCellChangeArgs e);
private void Form1_Load(object sender, EventArgs e)
{
this.Column1.DataGridViewTextChanged += new BCStainer.Classes.StainerApplication.EventCellChangeEvent(Column1_DataGridViewTextChanged);
}
void Column1_DataGridViewTextChanged(object sender, BCStainer.Classes.StainerApplication.EventCellChangeArgs e)
{
this.label1.Text = e.value;
}
运行时,Column1单元格的会和Textbox_change一样.
#14
#15
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
this.button1.Visible = true;
}
{
this.button1.Visible = true;
}
#16
刚好遇到此问题,进来参考一下
#17
解决问题了?
#18
有用!