简体   繁体   English

WinForm DevExpress Xtragrid以编程方式检查网格视图中的“指定”复选框列

[英]WinForm DevExpress Xtragrid programmatically to check Specified check box column in grid view

Explanation: 说明:

I have an grid view which contains RepositoryItemCheckEdit column's and RepositoryItemTextEdit column's,grid view contains column's like Item Id , Bar code , Pack Id etc 我有一个网格视图,其中包含RepositoryItemCheckEdit列和RepositoryItemTextEdit列,网格视图包含该列的类似Item IdBar codePack Id

1)RepositoryItemCheckEdit 1)RepositoryItemCheckEdit

Same Item Id and bar code can come multiple items in grid view with different pack id . 同一Item Idbar code可以在网格视图中具有不同pack id多个项目出现。

What I need is, if user selects any one item id's check box in grid view means i need all associated check box row's to be checked or unchecked viceversa. 我需要的是,如果用户在网格视图中选择了任何一个项目ID的复选框,则意味着我需要选中或取消选中所有关联的复选框行。 User may select either first check box or last check box then associated check box need to be checked or unchecked viceversa based upon user selection 用户可以选择第一个复选框或最后一个复选框,然后根据用户选择,需要选中或取消选中关联的复选框

2)RepositoryItemTextEdit 2)RepositoryItemTextEdit

Same as like check box Column Edit,Text edit Column Edit need to be worked such as if user enters 100 in item id column cell value means then corresponding Item id row's should also be assigned as 100 as follows 与复选框“列编辑”,“文本编辑”之类的复选框相同,例如,如果用户在“项目ID”列单元格值中输入100,则相应的“项目ID”行也应分配为100,如下所示

 void repchkCheckbox_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
    {
                DataTable dt_check = new DataTable();
                dt_check = (DataTable)gcItemMaster.DataSource;
                Int64 sItemId = Convert.ToInt64(gvItemMaster.GetRowCellValue(gvItemMaster.FocusedRowHandle, gvItemMaster.Columns["ItemID"]));
                bool bDiscount = Convert.ToBoolean(e.Value);
                int iItemcount = (from DataRow row in dt_check.Rows where (string)row["ItemID"] == "1" select row).Count();
                int iRowHandle = gvItemMaster.FocusedRowHandle;
                for (int i = 0; i < iItemcount; i++)
                {
                    if (bDiscount)
                        gvItemMaster.SetRowCellValue(iRowHandle, gvItemMaster.Columns["AllowDiscount"], true);
                    else
                        gvItemMaster.SetRowCellValue(iRowHandle, gvItemMaster.Columns["AllowDiscount"], false);

                    iRowHandle++;
                }
         }

Illustrative Purpose : if i contains 5 rows in gridview with same itemid but different packid... if i check very first row checkbox of itemId means i can easily able to populate remaining checkbox like 2nd,3rd,4th,5th through increamenting rowhandle value But My Question is if suppose i check 3 row of gridview Itemid checkbox means i can able to populate only 4th and 5th row of checkbox state..but 1st and 2nd row remains the same... 说明性目的:如果我在gridview中包含5行,且具有相同的itemid但具有不同的packid ...如果我仅检查第一行,则itemId的复选框表示我可以轻松地填充剩余的复选框,例如第2、3、4、5th个,而行的值不变我的问题是,如果假设我检查了3行gridview Itemid复选框,则意味着我只能填充复选框状态的第4行和第5行。但是第1行和第2行保持不变...

Do you have a field in your data table to represent the checked state? 数据表中是否有一个字段表示已检查状态?

If you do then you don't actually need to go via the grid. 如果这样做,则实际上不需要通过网格。 You can simply select the rows with a matching ID from the data table and set the relevant column to the value you want for each of those data rows. 您只需从数据表中选择具有匹配ID的行,然后将相关列设置为每个数据行所需的值。 The change will automatically be reflected in the grid. 更改将自动反映在网格中。

I Found the Solution It's works Perfectly: 我找到了解决方案,它的工作原理非常完美:

                     Int64 iItemId = Convert.ToInt64(gvItemMaster.GetRowCellValue(e.RowHandle, "ItemID"));
                     bool bDiscount = Convert.ToBoolean(e.Value);

                for (int i = 0; i < gvItemMaster.DataRowCount; i++)
                {
                    Int64 id = Convert.ToInt64(gvItemMaster.GetRowCellValue(i, "ItemID"));
                    if (id == iItemId)
                    {
                        if (bDiscount)
                            gvItemMaster.SetRowCellValue(i, gvItemMaster.Columns[""+sColumn.Replace(" ","")+""], true);
                        else
                            gvItemMaster.SetRowCellValue(i, gvItemMaster.Columns[""+sColumn.Replace(" ","")+""], false);
                    }
                }   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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