Unable to select multiple rows on infragistics ult

2019-08-15 02:47发布

I am having below code that successfully adds a check box column to the ultrawingrid, my problem is that when I make a selection by checking a check box on the Select column the count of selected rows of ultrawingrid is not updated and it still shows the count as zero, and also I want to know how to enable multi checkbox selection i.e multiple rows selected...

Below is the code...

private void grdPayVis_InitializeLayout(object sender,InitializeLayoutEventArgs e) 
 var gridBand = grdPayVis.DisplayLayout.Bands[0]; 
    if(!gridBand.Columns.Exists("Select"))
    gridBand.Columns.Add("Select", "Select");
gridBand.Columns["Select"].Header.VisiblePosition = 0; 
gridBand.Columns["Select"].Hidden = false; 
gridBand.Columns["Select"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox; 
gridBand.Columns["Select"].AutoSizeMode = ColumnAutoSizeMode.AllRowsInBand; 
gridBand.Columns["Select"].CellClickAction = CellClickAction.Edit; 

}

2条回答
时光不老,我们不散
2楼-- · 2019-08-15 03:12

I am not sure what you actually is trying to achieve. When you set CellClickAction in your Select column to Edit, and you click on any cell in this column the grid will select the cell and not the row. Grid has Selected property which exposes three collections - rows, columns and cells. In your case you are changing the selected cells and do not change the selected rows collection. If you need to select rows you need to set CellClickAction in your Select column to RowSelect. If you need in the same time to shange the checkbox state of the Select column you may handle AfterSelectChange event of the grid like this:

private void grdPayVis_AfterSelectChange(object sender, AfterSelectChangeEventArgs e)
{
    if (e.Type == typeof(UltraGridRow))
    {
        foreach (UltraGridRow row in this.grdPayVis.Selected.Rows)
        {
            row.Cells["Select"].Value = true; // Or some value appropriate to your scenario
        }

        this.grdPayVis.UpdateData();
    }   

By default, the grid allows you to select many cells, rows or columns. However, when there is a cell in edit mode you cannot select any other cells. So again, as you have set CellClickAction to Edit when you click any cell in Select column it enters edit mode and no more cells could be selected before you exit edit mode.

查看更多
小情绪 Triste *
3楼-- · 2019-08-15 03:20

You can add a new column to your datatable AFTER reading it from the database

ds = new DataSet("PayCharge"); 
ds= obj.GetData(); 
DataColumn dc = new DataColumn("Select", typeof(boolean));
dc.DefaultValue = false;
ds.Tables[0].Columns.Add(dc);
grdVisPay.SetDataBinding(ds, "PayCharge");  
.....

Now the first table in your dataset has an unbound column named Select and when you set that as your datasource you will be able to manipulate as you have already done. But this time whenever you touch the checkbox the value True/False will be set in the underlying datatable. When you need to discover what are the checked rows you work with the datasource, not with the grid. For example

void buttonSave_Click(object sender, EventArgs e)
{
     DataSet ds = grdVisPay.DataSource as DataSet;
     DataRows[] selectedRows = ds.Tables[0].Select("Select = True");
     foreach(DataRow row in selectedRows)
     {
         ... do whatever you need with the selected row...

     }
}
查看更多
登录 后发表回答