表格加下拉框

本文展示了一个使用C#编写的示例代码,该代码演示了如何遍历DataGridView中的每一行,并为特定列的DataGridViewComboBoxCell填充数据。通过调用不同的方法获取数据源并将其绑定到组合框中。
 

  foreach (DataGridViewRow row in this.dgvQueryAsk.Rows)
                {

                 
                    DataTable dtGet = ABC.getSupplyInfoForCombox(Convert.ToInt32(row.Cells["SerID"].Value));
                    if (dtGet.Rows.Count > 0)
                    {
                        object[] tels = new object[dtGet.Rows.Count];
                        for (int i = 0; i < dtGet.Rows.Count; i++)
                        {
                            tels[i] = dtGet.Rows[i][0];
                        }
                        this.BindCb(row, tels);
                    }
                                 
                    //DataTable employeeDataTable = objReSaleQueryDal.getEmployeeDataTableForGrid();
                    //if (employeeDataTable.Rows.Count > 0)
                    //{
                    //    object[] telsemployee = new object[employeeDataTable.Rows.Count];
                    //    for (int i = 0; i < employeeDataTable.Rows.Count; i++)
                    //    {
                    //        telsemployee[i] = employeeDataTable.Rows[i][0];
                    //    }
                    //   this.BindCbEmployee(row, telsemployee);
                    //}

                    this.BindCb_ColSupplyerLevel(row, new object[] { "--请选择--", "AB", "BC", "CE" });

                }
            }
   //private void BindCbEmployee(DataGridViewRow row, object[] tels)
        //{
        //    DataGridViewComboBoxCell aCBCell = row.Cells["ColEName"] as DataGridViewComboBoxCell;   //为DataGridViewComboBox列
        //    if (aCBCell != null)
        //    {
        //        aCBCell.Items.AddRange(tels);
        //        aCBCell.Value = tels[0];   //设置初始值的关键
        //    }
        //}

在 Vue 2 中使用 Ant Design Vue 对包含 `a-tree-select` 下表格进行校验,可借助 `a-form` 和 `a-form-model-item` 组件的校验功能。以下是一个示例代码: ```vue <template> <a-form ref="formRef" :model="ceshi" :rules="rules"> <a-table :columns="departmentColumns" :data-source="ceshi.departments" :pagination="false" bordered size="small" class="department-table" > <template #departmentId="{ text, record, index }"> <a-form-model-item :prop="`departments[${index}].departmentId`" :rules="rules.departments[index].departmentId"> <a-tree-select v-model="ceshi.departments[index].departmentId" :disabled="action === 'View'" :labelInValue="true" :treeData="treeList" :loadData="onLoadData" placeholder="请选择" /> </a-form-model-item> </template> <template #isMainDepartment="{ text, record, index }"> <a-checkbox v-model="ceshi.departments[index].isMainDepartment" @change="checkMain(index)"></a-checkbox> </template> <template #action="{ text, record, index }"> <div @click="deleteDepartmentBtn(index)"> <a-icon type="delete" /> </div> </template> </a-table> <a-button @click="handleSubmit">提交</a-button> </a-form> </template> <script> export default { data() { return { ceshi: { departments: [ { departmentId: null, isMainDepartment: false }, // 可以添加更多的初始数据 ], }, action: 'Edit', // 假设初始为编辑状态 treeList: [ // 树状数据 ], departmentColumns: [ { title: '部门 ID', dataIndex: 'departmentId', key: 'departmentId', }, { title: '是否主部门', dataIndex: 'isMainDepartment', key: 'isMainDepartment', }, { title: '操作', dataIndex: 'action', key: 'action', }, ], rules: { departments: [ { departmentId: [ { required: true, message: '请选择部门', trigger: 'change', }, ], }, // 如果有更多行,可以继续添加对应的规则 ], }, }; }, methods: { onLoadData() { // 加载树状数据的逻辑 }, checkMain(index) { // 处理是否主部门的逻辑 }, deleteDepartmentBtn(index) { // 删除部门的逻辑 this.ceshi.departments.splice(index, 1); this.rules.departments.splice(index, 1); }, handleSubmit() { this.$refs.formRef.validate((valid) => { if (valid) { console.log('表单验证通过', this.ceshi); // 可以在这里进行提交表单等操作 } else { console.log('表单验证失败'); } }); }, }, }; </script> ``` ### 代码解释 - `a-form` 和 `a-form-model-item`:用于包裹 `a-table`,从而启用表单的校验功能。 - `rules`:定义了表单的校验规则,对于 `departmentId` 字段,设置了 `required: true` 表示该字段为必选,同时设置 `message` 为校验不通过时显示的提示信息。 - `validate` 方法:在提交表单时调用 `validate` 方法,对表单进行校验。如果校验通过,会执行成功的回调函数;如果校验不通过,会执行失败的回调函数。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CPU_2

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值