c# - How To Display Multiple Rows in XamGrid -


i using listbox control show items , when double cilck item means thier particular item fields display in xamgrid , problem when selected item means showing need display multiple things in grid 1 or more items

my codings are,

private void lsimagegallery_mousedoubleclick(object sender, mousebuttoneventargs e)         {             rtbsproject.db.rtbsinventorymgmtentities2 myrtbsinventorydb = new db.rtbsinventorymgmtentities2();              rtbsproject.db.rtbsinventorymgmtentities2 db_linq = new db.rtbsinventorymgmtentities2();          try         {          string curitem = lsimagegallery.selecteditem.tostring();          #region          if (cmbitemcombo.selecteditem == null)         {               var selectedimage = (imageentity)this.lsimagegallery.selecteditem;              string itemname = selectedimage.itemname_en;              var query = (from myitems in myrtbsinventorydb.tbl_itemmaster                          myitems.activeflag == true &&                          myitems.itemname_en == itemname                          select myitems).tolist();              xamgrid1.itemssource = query; } 

every time displaying 1 record ,if selected second 1 means previous selected should not clear both should display please me..

i'm not 100% sure you're asking here i'll have go anyway. looks me you're trying add more rows datagrid instead new items being displayed.

this because you're changing itemssource property of datagrid, if want new items added bottom itemssource needs stay same , add new rows.

this can either done items.add() method on datagrid, loop on data rows , call add each 1 or create collection of items add on double click, i've provided example of second here.

like application shows listbox , datagrid, each time double click on item in listbox few more rows added datagrid.

xaml

 <window x:class="wpfapplication1.mainwindow"             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"             datacontext="{binding relativesource={relativesource self}}"             title="mainwindow" height="350" width="525">         <grid>             <grid.columndefinitions>                 <columndefinition/>                 <columndefinition/>             </grid.columndefinitions>             <listbox grid.column="0" itemssource="{binding items}" mousedoubleclick="listbox_mousedoubleclick"/>             <datagrid grid.column="1" itemssource="{binding griditems}">                 <datagrid.columns>                     <datagridtextcolumn binding="{binding}"/>                 </datagrid.columns>             </datagrid>         </grid>     </window> 

code behind

using system; using system.collections.objectmodel; using system.windows; using system.windows.input;  namespace wpfapplication1 {     public partial class mainwindow : window     {         // collection bound listbox there items select from.         public observablecollection<object> items         {             { return (observablecollection<object>)getvalue(itemsproperty); }             set { setvalue(itemsproperty, value); }         }         public static readonly dependencyproperty itemsproperty =             dependencyproperty.register("items", typeof(observablecollection<object>), typeof(mainwindow), new propertymetadata(null));          // on double click of each item in listbox more items added collection.         public observablecollection<object> griditems         {             { return (observablecollection<object>)getvalue(griditemsproperty); }             set { setvalue(griditemsproperty, value); }         }                public static readonly dependencyproperty griditemsproperty =             dependencyproperty.register("griditems", typeof(observablecollection<object>), typeof(mainwindow), new propertymetadata(null));          public mainwindow()         {             initializecomponent();              // demo items can double click.             items = new observablecollection<object>();             items.add("test item 1");             items.add("test item 2");             items.add("test item 3");             items.add("test item 4");             items.add("test item 5");             items.add("test item 6");             items.add("test item 7");              griditems = new observablecollection<object>();         }          private void listbox_mousedoubleclick(object sender, mousebuttoneventargs e)         {             // these entries database, i'm going add random numbers.             random rnd = new random();              (int = 0; < rnd.next(5); i++)                 griditems.add(rnd.next(100));         }     } } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -