一、給gridcontrol添加按鈕列
最近搞項目,要給crigcontrol添加按鈕列。由于英文不好走了很多彎路。
現在終于搞好了。。
寫下來,以防以後忘記
把列的columnedit屬性設定為repositoryitembuttonedit
把texteditstyle屬性設定為hidetexteditor;
把buttons的kind屬性設定為glyph;
把buttons的horzalignment屬性設定為near;
如果要用到事件的話,還要注冊事件。。。
列名.buttonclick += new buttonpressedeventhandler(列名_buttonclick);
二、gridcontrol中的cardview中 圖檔不顯示的問題
//顯示資料
private void showdata()
{
datatable dt = new datatable("oneemployee");
dt.columns.add("caption", system.type.gettype("system.string"));
dt.columns.add("department", system.type.gettype("system.string"));
dt.columns.add("photoname", system.type.gettype("system.byte[]"));
datarow dr = dt.newrow();
dr["caption"] = list[i].name;
dr["department"] = list[i].department;
string imagepath = @"d:/c#/photos/" + list[i].photopath;
dr["photoname"] = getimagebyte(imagepath);
dt.rows.add(dr);
gridcontrol1.datasource = dt;
}
//傳回圖檔的位元組流byte[]
private byte[] getimagebyte(string imagepath)
filestream files = new filestream(imagepath, filemode.open);
byte[] imgbyte = new byte [files.length ];
files.read(imgbyte, 0, imgbyte.length);
files.close();
return imgbyte;
}