0

我需要修改 datagridview 内的按钮名称的描述

我正在使用 DevExpress - WindowsForm - C#

如何根据单元格“TYPE”的值自动逐行更改按钮?

例如:在“类型”列中,当单元格值为“服务”时,按钮显示说明“接收”,当单元格值为“费用”时,按钮说明显示为“立即付款”。

在此处输入图像描述

4

2 回答 2

0
foreach (DataGridViewRow dgr in dataGridView1.Rows)
            {

                if (!dgr.IsNewRow)
                {
                    if (dgr.Cells[3].Value=="SERVICE")
                    {
                        dgr.Cells[4].Value = "Receive"; 
                    }
                    else if (dgr.Cells[3].Value == "Expense")
                    {
                        dgr.Cells[4].Value = "Pay now"; 
                    }
                }
            }
于 2021-05-04T08:11:17.930 回答
0

我尝试这样做,但是“for”正在将按钮描述分配给所有单元格,而正确的描述应该只针对那些“TYPE”彼此不同的单元格,我做错了什么?

    private void bandedGridView1_CellValueChanged(object sender, CellValueChangedEventArgs e)
    {
        BandedGridView view = sender as BandedGridView;
        if (view == null) return;

        if (e.Column.Caption == "BUTTON")
        {
            var value = bandedGridView1.GetFocusedRowCellValue("TYPE");
                           
            if ( value == "SERVICE")
            {

                for (int i = 0; i < bandedGridView1.DataRowCount; i++)
                {
                    DataRow row = bandedGridView1.GetDataRow(i);
                    
                    RepositoryItemButtonEdit riButton = new RepositoryItemButtonEdit();

                    riButton.TextEditStyle = TextEditStyles.HideTextEditor;

                    riButton.Buttons[0].Kind = ButtonPredefines.Glyph;
                    riButton.Buttons[0].Caption = "Receive";
                    
                    riButton.ButtonClick += AcaoBotaoDataGrid_ButtonClick;
                    dtgQuadroSorteio.RepositoryItems.Add(riButton);
                    bandedGridColumn1.ColumnEdit = riButton;

                }

            }
            else if (value == "EXPENSE")
            {
               for (int i = 0; i < bandedGridView1.DataRowCount; i++)
                {
                    DataRow row = bandedGridView1.GetDataRow(i);
                    
                    RepositoryItemButtonEdit riButton = new RepositoryItemButtonEdit();

                    riButton.TextEditStyle = TextEditStyles.HideTextEditor;

                    riButton.Buttons[0].Kind = ButtonPredefines.Glyph;
                    riButton.Buttons[0].Caption = "Pay now";
                    
                    riButton.ButtonClick += AcaoBotaoDataGrid_ButtonClick;
                    dtgQuadroSorteio.RepositoryItems.Add(riButton);
                    bandedGridColumn1.ColumnEdit = riButton;

                }
            }
           
        }

在此处输入图像描述

于 2021-05-04T13:05:41.873 回答