加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

winforms – Infragistics的Checkbox专栏赢得了ultragrid

发布时间:2020-12-14 18:27:19 所属栏目:资源 来源:网络整理
导读:是Infragistics的新手. 在我的 winforms应用程序上,我使用Ultrawingrid显示数据库中的数据. 如何将复选框列显示为网格中的第一列? 此外,我需要捕获check / uncheck事件,然后读取应用程序中相应的网格行/单元格. 你能帮帮我吗? 谢谢阅读. 解决方法 您需要获
是Infragistics的新手.
在我的 winforms应用程序上,我使用Ultrawingrid显示数据库中的数据.

如何将复选框列显示为网格中的第一列?
此外,我需要捕获check / uncheck事件,然后读取应用程序中相应的网格行/单元格.

你能帮帮我吗?

谢谢阅读.

解决方法

您需要获取要作为复选框呈现的列的UltraGridColumn实例.就像是:
UltraGridColumn ugc = myGrid.DisplayLayout.Bands[0].Columns[@"myColumnKey"];

然后将列的显示样式更改为复选框,并确保它允许编辑:

ugc.Style = ColumnStyle.CheckBox;
ugc.CellActivation = Activation.AllowEdit;

在我看来,在表单的Load事件或网格的InitializeLayout事件的处理程序中使用此网格初始化代码是合适的.

处理网格的CellChange事件以查看用户何时更改复选框值:

private void mygrid_CellChange(object sender,CellEventArgs e)
{
    if (StringComparer.OrdinalIgnoreCase.Equals(e.Cell.Column.Key,@"myColumnKey"))
    {
         // do something special when the checkbox value is changed
    }
}

根据要求,下面是示例代码,演示添加未绑定列,将其移动到最左侧位置,处理单元格更改事件以及从网格中检索其他值.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender,EventArgs e)
    {
        using (SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=tempdb;Trusted_Connection=true"))
        {
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter("select * from sysobjects",conn);
            conn.Open();
            da.Fill(ds); 
            ultraGrid1.DataSource = ds;
        }
    }

    private void ultraGrid1_InitializeLayout(object sender,Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
    {
        UltraGridColumn checkColumn = e.Layout.Bands[0].Columns.Add(@"checkColumnKey",@"caption");
        checkColumn.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
        checkColumn.CellActivation = Activation.AllowEdit;
        checkColumn.Header.VisiblePosition = 0;
    }

    private void ultraGrid1_CellChange(object sender,CellEventArgs e)
    {
        if (!StringComparer.Ordinal.Equals(e.Cell.Column.Key,@"checkColumnKey"))
        {
            return;
        }

        bool checkedState = bool.Parse(e.Cell.Text);

        DataRowView row = e.Cell.Row.ListObject as DataRowView;
        string name = row.Row[@"name"] as string;

        MessageBox.Show(string.Format("Checked={0},name={1}",checkedState,e.Cell.Row.ListObject));
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读