关于datagrid的问题,如何使行宽不可由用户更改.(即行宽固定,不能通过拖拉的方式改变)定义datagrid的时候就把宽度设定<asp:boundcolumn ...> <headerstyle width="150px"></headerstyle>
textbox1.text=mydatagrid(mydatagrid.currentcell.rownumber,0)textbox2.text=mydatagrid(mydatagrid.currentcell.rownumber,1)........ 【程序编程相关:使用模板列获取批量获取DataGrid中】
如何在winform中datagrid点击某行,使数据实时显示在textbox中?datagrid的keypress事件中 【推荐阅读:自己用C#开发的EMAIL地址抓取程序。】
namespace datagriddoubleclick{ using system; using system.drawing; using system.collections; using system.componentmodel; using system.windows.forms; using system.data; 【扩展信息:什么是Web Service? 】
以此类推
public class form1 : system.windows.forms.form { private system.windows.forms.datagrid datagrid1; private dataset mydataset; datetime gridmousedowntime; private system.windows.forms.label label1; private system.componentmodel.container components = null;
public form1() { initializecomponent(); gridmousedowntime = datetime.now; setup(); }
private void setup() { // 用2个table与1与relation创建dataset makedataset(); // 数据绑定 datagrid1.setdatabinding(mydataset, "customers");
//添加样式 addcustomdatatablestyle(); }
private void makedataset() { // 创建dataset. mydataset = new dataset("mydataset"); // 创建2个datatables. datatable tcust = new datatable("customers"); // 创建两个列,并添加到第一个表 datacolumn ccustid = new datacolumn("custid"); datacolumn ccustname = new datacolumn("custname"); datacolumn ccurrent = new datacolumn("custcity"); tcust.columns.add(ccustid); tcust.columns.add(ccustname); tcust.columns.add(ccurrent);
// 把tables添加到dataset. mydataset.tables.add(tcust); /* 计算tables.对每个客户,创建datarow变量 */ datarow newrow1; // 添加记录到 customers table. for(int i = 1; i < 4; i++) { newrow1 = tcust.newrow(); newrow1["custid"] = (100*i).tostring(); tcust.rows.add(newrow1); }
tcust.rows[0]["custname"] = ""; tcust.rows[1]["custname"] = "net_lover"; tcust.rows[2]["custname"] = "http://xml.sz.luohuedu.net/";
tcust.rows[0]["custcity"] = "北京"; tcust.rows[1]["custcity"] = "上海"; tcust.rows[2]["custcity"] = "河南"; }
private void addcustomdatatablestyle() { datagridtablestyle ts1 = new datagridtablestyle(); ts1.mappingname = "customers"; // 设置属性 ts1.alternatingbackcolor = color.lightgray;
// 添加textbox列样式,以便我们捕捉鼠标事件 datagridtextboxcolumn textcol = new datagridtextboxcolumn(); textcol.mappingname = "custid"; textcol.headertext = "序号"; textcol.width = 100;
//添加事件处理器 textcol.textbox.mousedown += new mouseeventhandler(textboxmousedownhandler); textcol.textbox.doubleclick += new eventhandler(textboxdoubleclickhandler); ts1.gridcolumnstyles.add(textcol);
textcol = new datagridtextboxcolumn(); textcol.mappingname = "custname"; textcol.headertext = "姓名"; textcol.width = 100; //添加事件处理器 textcol.textbox.mousedown += new mouseeventhandler(textboxmousedownhandler); textcol.textbox.doubleclick += new eventhandler(textboxdoubleclickhandler); ts1.gridcolumnstyles.add(textcol);
textcol = new datagridtextboxcolumn(); textcol.mappingname = "custcity"; textcol.headertext = "地址"; textcol.width = 100; //添加事件处理器 textcol.textbox.mousedown += new mouseeventhandler(textboxmousedownhandler); textcol.textbox.doubleclick += new eventhandler(textboxdoubleclickhandler); ts1.gridcolumnstyles.add(textcol); datagrid1.tablestyles.add(ts1); }
protected override void dispose( bool disposing ) { if( disposing ) { if (components != null) { components.dispose(); } } base.dispose( disposing ); }
... 下一页