惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MyScale Blog
MyScale Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
Y
Y Combinator Blog
月光博客
月光博客
IT之家
IT之家
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
L
LangChain Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
博客园 - Franky
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
V
Visual Studio Blog
小众软件
小众软件
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium

博客园 - Box

ASP.NET 配置文件层次结构和继承(转) NetAdvantage 2007 CLR1x ASPNET 注册码 SN 处理SPS错误:只有在配置文件或 Page 指令中将启用会话状态设置为真时,才可以使用会话状态 - Box C# 处理xml(转) 关于版权声明的写法(转) 编写优秀技术文档的技巧(转) 教你怎样做项目开发总结报告(转) 如何编写高质量软件需求说明书(转) 如何编写企业解决方案书(转) 如何编写高质量的需求(转) 如何写好测试报告(转) 如何写系统分析书(转) Macromedia Captivate 使用手册(转) 改变你一生的五句话 (转) Windows 使用FTP批处理脚本(转) professional C# 2005 下载地址 Windows 安装组件注意事项 SQLServer数据库完整迁移(转) 计算字段.
让DataGridView 带*号的一行不显示!
Box · 2006-12-08 · via 博客园 - Box

How do I prevent the datagrid from displaying its append row (the row at the end with an asterisk)?
原文:http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q653q

The DataGrid class does not have a property that controls whether a new row can be added. But the DataView class does have such a property (along with some others such as AllowEdit and AllowDelete). Here is code that will turn off the append row by getting at the dataview associated with the datagrid.

     string connString = @"Provider=Microsoft.JET.OLEDB.4.0;data source=C:\northwind.mdb"
     
string sqlString = "SELECT * FROM customers"
 
         
// Connection object 
     OleDbConnection connection = new OleDbConnection(connString); 
  
     
// Create data adapter object 
     OleDbDataAdapter dataAdapter = new OleDbDataAdapter(sqlString, connection); 
  
     
// Create a dataset object and fill with data using data adapter's Fill method 
     DataSet dataSet = new DataSet(); 
     dataAdapter.Fill(dataSet, 
"customers"); 
  
     
// Attach dataset's DefaultView to the datagrid control 
    dataGrid1.DataSource = dataSet.Tables["customers"]; 
     
//no adding of new rows thru dataview 
     CurrencyManager cm = (CurrencyManager)this.BindingContext[dataGrid1.DataSource, dataGrid1.DataMember];      
     ((DataView)cm.List).AllowNew 
= false;

If your datagrid contains links, then Matthew Miller suggest adding Navigate handler such as the one below to disallow the AddNew.

private void DataGrid1_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne) 

     
if(ne.Forward) 
     

          CurrencyManager cm 
= (CurrencyManager)BindingContext[DataGrid1.DataSource,DataGrid1.DataMember]; 
          DataView dv 
= (DataView) cm.List; 
          dv.AllowNew 
= false
     }
 
}