本文介绍了在数据绑定 datagridview 中添加按钮列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据网格视图.我将它绑定到一个列表.现在我想在它的末尾显示一列.但是那一栏好像错位了.

i have a datagridview. i bound it to a list. now i want to show a column at the end of it. but that column apprear in wrong possition.

这是我的代码

    grdPatientAppointment.DataSource = lst;


        grdPatientAppointment.Columns["ID"].Visible = false;
        //grdPatientAppointment.Columns["AdmitDate"].Visible = false;
        //grdPatientAppointment.Columns["DischargeDate"].Visible = false;
        grdPatientAppointment.Columns["AppointmentID"].Visible = false;

        grdPatientAppointment.Columns["PatientrName"].DisplayIndex = 0;
        grdPatientAppointment.Columns["Age"].DisplayIndex = 1;
        grdPatientAppointment.Columns["Address"].DisplayIndex = 2;
        grdPatientAppointment.Columns["ContactNo"].DisplayIndex = 3;
        grdPatientAppointment.Columns["Dieseas"].DisplayIndex = 4;
        grdPatientAppointment.Columns["AppointmentDate"].DisplayIndex = 5;

        DataGridViewButtonColumn btnColumn = new DataGridViewButtonColumn();
        btnColumn.HeaderText = "Treat";
        btnColumn.Text = "Treat";
        btnColumn.UseColumnTextForButtonValue = true;
        grdPatientAppointment.Columns.Insert(6,btnColumn);

这里是输出:

但我希望该按钮位于数据网格视图的末尾

but i want that button to the end of datagrid view

推荐答案

添加列而不是将其插入到 GridView.它会自动将其附加到列集合的末尾.

Add column instead of inserting it to the GridView. It will automaticallyy append it to the end of column collection.

    grdPatientAppointment.Columns.Add(btnColumn);

这篇关于在数据绑定 datagridview 中添加按钮列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 00:25