我在datagrid控件里显示一个表的信息,我想实现点击其中一个字段,则该字段对应的整行都显示被选中颜色,这个用代码怎么实现。
我在datagrid控件里显示一个表的信息,我想实现点击其中一个字段,则该字段对应的整行都显示被选中颜色,这个用代码怎么实现。
------解决方案--------------------DateGrid 的Created事件中添加 
 e.Row.Attributes.Add( "onclick ",  "if(window.oldtr!=null){window.oldtr.runtimeStyle.cssText= ' ';}this.runtimeStyle.cssText= 'background-color:#e6c5fc ';window.oldtr=this ");
------解决方案--------------------	internal class DataGridNoActiveCellColumn : System.Windows.Forms.DataGridTextBoxColumn 
 	{ 
 		//重载DataGridTextBoxColumn类的Edit方法,以便使点击DataGrid中任一单元格都选中当前行 
 		protected override void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible) 
 		{ 
 			int SelectedRow = rowNum; 
 			this.DataGridTableStyle.DataGrid.Select(SelectedRow); 
 		} 
 	} 
 然后在DataGridStateControl中 
 			for (int i = 0;i < numCols;i++) 
 			{ 
 				DataGridNoActiveCellColumn	aColumnTextColumn = new DataGridNoActiveCellColumn(); 
 即可