简体   繁体   中英

Unable to select multiple rows on infragistics ultrawingrid with a check box column

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 ie 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; 

}

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...

     }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM