本文介绍了在数据绑定datagridview中添加按钮列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个datagridview。我把它绑定到一个列表。现在我想在其末尾显示一列。但是这一列令人不解之缘。这是我的代码
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 =对待;
btnColumn.Text =对待;
btnColumn.UseColumnTextForButtonValue = true;
grdPatientAppointment.Columns.Insert(6,btnColumn);
这里输出:
但我希望该按钮到最后的datagrid视图
解决方案
添加列而不是将其插入到GridView中。它将自动将其附加到列收集的末尾。
grdPatientAppointment.Columns.Add(btnColumn);
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.
this is my code
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);
here is output:
but i want that button to the end of datagrid view
解决方案
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中添加按钮列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!