表事件中一般有两个参数,第一个object类型的参数,名字叫sender,这个就是表本身,我们可以直接通过这个参数获得对触发事件的这个表的引用。第二个参数是一个e参数,主要是根据事件的特性返回的e参数的类型也不尽相同。一般情况下,e参数返回的就是与此事件相关的信息。
注意,如果触发事件的表是SmEditTreeGrid,那么我们就得直接转化成SmEditTreeGrid再使用。比如:Dim tbl as
SmEditTreeGrid=sender
下面为常规的几种常见的e参数类型
Vb.Net |
Public Sub SmGrid1_Click(sender As Object,e As System.EventArgs)
'系统默认参数,此参数一般得不到任何有效的信息
'在此类事件中,如果我们想获得当前行的话,可以通过表的CurrentRowData属性获得
Dim tbl As SmGrid=sender
Dim dr As RowData=tbl.CurrentRowData
End Sub
Public Sub SmGrid1_MouseDoubleClick(sender As Object,e As System.Windows.Forms.MouseEventArgs)
'与鼠标相关的参数,可以获得鼠标的坐标,进而可以通过HitTest获得HitTestInfo
Dim tbl As SmGrid=sender
Dim hit As HitTestInfo=tbl.HitTest(e.X,e.Y)
End Sub
Public Sub SmGrid1_BeforeSave(sender As Object,e As System.ComponentModel.CancelEventArgs)
Dim tbl As SmGrid=sender
'可以取消的有参数,一般此参数可以设置Cancel=True以取消动作继续执行
If tbl.CheckDataRuleBeforeSave(True) Then
e.Cancel=True
End If
End Sub
Public Sub SmGrid1_ColDataChanged(sender As Object,e As sanMuSoft.CS.WinForm.ColDataEventArgs)
Dim tbl As SmGrid=sender
'ColData变更事件,包含了下面这些对象
Dim dt As DataTableHelp=e.DataTableHelp
Dim col As ColData=e.ColData
Dim dr As RowData=e.RowData
Dim objOld As Object=e.OldValue
Dim objNew As Object=e.NewValue
Dim frm As BaseForm=e.Form
End Sub
Public Sub SmGrid1_RowDataAdded(sender As Object,e As sanMuSoft.CS.WinForm.RowDataEventArgs)
Dim tbl As SmGrid=sender
'RowData变更事件,包含下面这些对象
Dim dt As DataTableHelp=e.DataTableHelp
Dim dr As RowData=e.RowData
Dim frm As BaseForm=e.Form
End Sub
Public Sub SmGrid1_CellButtonClick(sender As Object,e As C1.Win.C1FlexGrid.RowColEventArgs)
Dim tbl As SmGrid=sender
'表中RowCol参数主要包含行、列值
Dim intRow As Integer=e.Row
Dim intCol As Integer=e.Col
'我们可以依据行列信息进而获得
Dim strColName As String=tbl.Cols(intCol).Name
'获得ColData对象
Dim dc As ColData=tbl.DataTableHelp.DataCols(strColName)
'获得ColBase对象
Dim dvc As ColBase=tbl.View.ViewCols(strColName)
'获得RowData对象
Dim dr As RowData=tbl.Rows(intRow).GetRowData()
End Sub
Public Sub SmGrid1_OwnerDrawCell(sender As Object,e As C1.Win.C1FlexGrid.OwnerDrawCellEventArgs)
Dim tbl As SmGrid=sender
'可以获得行、列值,那么就可以获得其他类型的行列信息了。
Dim intRow As Integer=e.Row
Dim intCol As Integer=e.Col
'其他可获得的对象,下面这些对象主要是用来绘画单元格内容的
Dim g As Graphics=e.Graphics
Dim img As Image= e.Image
Dim str As String=e.Text
Dim style As CellStyle=e.Style
Dim rec As Rectangle=e.Bounds
End Sub
|
C#
|
public void SmGrid1_Click(object sender, System.EventArgs e)
{
// 系统默认参数,此参数一般得不到任何有效的信息
// 在此类事件中,如果我们想获得当前行的话,可以通过表的CurrentRowData属性获得
SmGrid tbl = sender as SmGrid;
RowData dr = tbl.CurrentRowData;
}
public void SmGrid1_MouseDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e)
{
// 与鼠标相关的参数,可以获得鼠标的坐标,进而可以通过HitTest获得HitTestInfo
SmGrid tbl = sender as SmGrid;
HitTestInfo hit = tbl.HitTest(e.X, e.Y);
}
public void SmGrid1_BeforeSave(object sender, System.ComponentModel.CancelEventArgs e)
{
SmGrid tbl = sender as SmGrid;
// 可以取消的有参数,一般此参数可以设置Cancel=True以取消动作继续执行
if (tbl.CheckDataRuleBeforeSave(true))
e.Cancel = true;
}
public void SmGrid1_ColDataChanged(object sender, sanMuSoft.CS.WinForm.ColDataEventArgs e)
{
SmGrid tbl = sender as SmGrid;
// ColData变更事件,包含了下面这些对象
DataTableHelp dt = e.DataTableHelp;
ColData col = e.ColData;
RowData dr = e.RowData;
object objOld = e.OldValue;
object objNew = e.NewValue;
BaseForm frm = e.Form;
}
public void SmGrid1_RowDataAdded(object sender, sanMuSoft.CS.WinForm.RowDataEventArgs e)
{
SmGrid tbl = sender as SmGrid;
// RowData变更事件,包含下面这些对象
DataTableHelp dt = e.DataTableHelp;
RowData dr = e.RowData;
BaseForm frm = e.Form;
}
public void SmGrid1_CellButtonClick(object sender, C1.Win.C1FlexGrid.RowColEventArgs e)
{
SmGrid tbl = sender as SmGrid;
// 表中RowCol参数主要包含行、列值
int intRow = e.Row;
int intCol = e.Col;
// 我们可以依据行列信息进而获得
string strColName = tbl.Cols[intCol].Name;
// 获得ColData对象
ColData dc = tbl.DataTableHelp.DataCols[strColName];
// 获得ColBase对象
ColBase dvc = tbl.View.ViewCols[strColName];
// 获得RowData对象
RowData dr = tbl.Rows[intRow].GetRowData();
}
public void SmGrid1_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e)
{
SmGrid tbl = sender as SmGrid;
// 可以获得行、列值,那么就可以获得其他类型的行列信息了。
int intRow = e.Row;
int intCol = e.Col;
// 其他可获得的对象,下面这些对象主要是用来绘画单元格内容的
Graphics g = e.Graphics;
Image img = e.Image;
string str = e.Text;
CellStyle style = e.Style;
Rectangle rec = e.Bounds;
}
|