2011-05-22 60 views
6

我有一个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 = "Treat"; 
     btnColumn.Text = "Treat"; 
     btnColumn.UseColumnTextForButtonValue = true;    
     grdPatientAppointment.Columns.Insert(6,btnColumn); 

这里是输出:

here is output

,但我想,按钮,数据网格视图的最后

回答

4

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

grdPatientAppointment.Columns.Add(btnColumn); 
0

只需添加下面

grdPatientAppointment.Columns.Insert(I, btnColumn) 

我的代码是列的索引要添加

0

使用grdPatientAppointment.AutoGenerateColumns = false;

然后添加的所有列网格将收到来自数据源和它们绑定来自编辑。

相关问题