c# - How to show an image in imagebox and specify a value for combo when i select a row of dateagrid? -
i field of table , show them in datagrid code:
in xaml:
<datagrid x:name="dgvaddpersontab" height="158" width="396" autogeneratecolumns="false" canuserdeleterows="false" selectionchanged="dgvaddpersontab_selectionchanged" canvas.left="520" canvas.top="20"> <datagrid.columns> <datagridtextcolumn binding="{binding firstname}" width="78" /> <datagridtextcolumn binding="{binding family}" width="80" /> <datagridtextcolumn binding="{binding departmentname}" width="78" /> <datagridtextcolumn binding="{binding occupation}" width="80" /> <datagridtextcolumn binding="{binding personalcardno}" width="78" /> </datagrid.columns> </datagrid>
and in code behind:
var queryofdgvaddperson = j in facedb.tblknownpeoples join m in facedb.tbldepartments on j.iddepartment equals m.iddepartment select new { j.firstname, j.family, m.departmentname, j.occupation, j.personalcardno, j.birthdate, j.fathername, j.fifthpicaddress, j.firstpicaddress, j.fourthpicaddress, j.iddepartment, j.nationalidcardno, j.phone, j.secondpicaddress, j.thirdpicaddress }; dgvaddpersontab.itemssource = queryofdgvaddperson.tolist();
now, want when select row in datagrid, fields corresponding row in table shown in textbox , combo , imagebox. can fields follow code:
object ob = datagrid.selecteditem;
but can't show them, have problem combo , imagebox. must in field corresponding imagebox saved address of image.
updated: found way show string fetch table in textbox can't still have found way show image address , combovalue.
public ienumerable<datagridrow> getdatagridrows(datagrid grid) { var itemssource = grid.itemssource ienumerable; if (null == itemssource) yield return null; foreach (var item in itemssource) { var row = grid.itemcontainergenerator.containerfromitem(item) datagridrow; if (null != row) yield return row; } } private void dgvaddpersontab_selectionchanged(object sender, selectionchangedeventargs e) { var row_list = getdatagridrows(dgvaddpersontab); foreach (datagridrow single_row in row_list) { if (single_row.isselected == true) { txtname.text = convert.tostring(typedescriptor.getproperties(single_row.datacontext)["firstname"].getvalue(single_row.datacontext)); } } }
second update:
suppose have 2 table named person
, officeaccess
. in person
i'll save staffs of office , in officeaccess
save access of staffs office's building. person
has field: idknown
, name
, family
, phone
, idaccess
, officeaccess
has field: idaccess
, accessdeccription
. idaccess
foreign key in person have reference officeaccess
, idaccess
column. now, after long intro(!), value of combo come officeaccess
, accessdeccription
.
i try follow code wrong:
cmbaccessofoffice.displaymemberpath = dgvaddpersonallfeilds.gettype().getproperty("departmentname").getvalue(dgvaddpersonallfeilds, null).tostring();
i think looking this
var obj = dgvaddpersontab.selecteditem; var nameofproperty = "departmentname"; var propertyinfo = obj.gettype().getproperty(nameofproperty); var value = propertyinfo.getvalue(obj, null); img.source = new bitmapimage(new uri(value.tostring()));
combobox:
when creating combobox need set selectedvaluepath.and can use same method above select combobox value
var obj = dgvaddpersontab.selecteditem; var nameofproperty = "comoboxproperty"; var propertyinfo = obj.gettype().getproperty(nameofproperty); var value = propertyinfo.getvalue(obj, null); cmbaccessofoffice.selectedvalue=value ;
Comments
Post a Comment