DX使用随记--GridControl

1. 获取DataView行数据:

(1)dv.Table.Rows[0]["price"].ToString()  

这种方法虽然很长,但意思很清晰。

(2)dv[0]["price"].ToString()

因为dv[i]方法可以为获取到指定的行记录,接下来的["price"],通过指定属性名便可以获取相应列的值了。第二种方法比较短,因为不必获取其Table,效率估计应该会更高一些。

 

2.DevExpress GridView 显示行号:

vb.net:

 Private Sub GridView1_CustomDrawRowIndicator(sender As Object, e As RowIndicatorCustomDrawEventArgs) Handles GridView1.CustomDrawRowIndicator
  '行号
  If e.Info.IsRowIndicator And e.RowHandle >= 0 Then
    e.Info.DisplayText = e.RowHandle + 1
  End If
End Sub
 
------------------------------------------------------------------------------------------------------------
 

C#:

    private void dataGridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
     {
        if (e.Info.IsRowIndicator)
        {
            e.Info.DisplayText = Convert.ToString(e.RowHandle + 1);
         }
     }

我们再看一下vs自带的dataGridView中行号的实现方法

 

private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
               e.RowBounds.Location.Y,
               dataGridView1.RowHeadersWidth - 4,
               e.RowBounds.Height);

            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                dataGridView1.RowHeadersDefaultCellStyle.Font,
                rectangle,
                dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }

 

 

 
 
 
 
 

 

posted @ 2019-04-30 17:02  淡羽  阅读(544)  评论(0编辑  收藏  举报