2013-07-17 2 views
0

ListBox 컨트롤을 사용하여 항목을 표시 할 때 및 항목을 두 번 표시 할 때 항목을 지정하면 해당 항목 필드가 xamgrid에 표시되고 선택한 항목은 표시되지만 표시해야 할 때 문제가 발생 함을 의미합니다. 내가 두 번째는 모두가 저를 도와주세요 표시되어야 취소 안 선택 이전의 의미를 선택한 경우 하나 개 이상의 항목XamGrid에서 여러 행을 표시하는 방법

내 코딩이 있습니까,

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 
         where MyItems.ActiveFlag == true && 
         MyItems.ItemName_EN == ItemName 
         select MyItems).ToList(); 

      xamGrid1.ItemsSource = query; 
} 

에 대한 그리드의 여러 가지마다 그는 하나 개의 레코드를 표시 ..

+0

하시기 바랍니다 어떤 하나 개의 응답 뒤에 – user2568244

답변

0

저는 100 % 당신이 여기에서 묻고있는 것이 확실하지는 않지만 어쨌든 나는 갈 것입니다. DataGrid에 행을 추가하려고하지만 새 항목 만 표시되는 것처럼 보입니다.

DataGrid의 ItemsSource 속성을 변경하려고합니다. 새 항목을 맨 아래에 추가하고 ItemsSource를 동일하게 유지하고 새 행을 추가해야하는 경우입니다.

DataGrid의 Items.Add() 메서드를 사용하여 수행 할 수 있으며 데이터 행을 반복하고 각 행에 대해 add를 호출하거나 두 번 클릭 할 때 추가 할 항목의 컬렉션을 만들 수 있습니다. 여기에 두 번째 예가 나와 있습니다.

응용 프로그램처럼 ListBox와 DataGrid를 표시하므로 ListBox에서 항목을 두 번 클릭 할 때마다 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> 

코드

using System; 
using System.Collections.ObjectModel; 
using System.Windows; 
using System.Windows.Input; 

namespace WpfApplication1 
{ 
    public partial class MainWindow : Window 
    { 
     // This collection is bound to the ListBox so there are items to select from. 
     public ObservableCollection<object> Items 
     { 
      get { 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 the ListBox more items will be added to this collection. 
     public ObservableCollection<object> GridItems 
     { 
      get { 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(); 

      // Some demo items so we 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 would be the entries from your database, I'm going to add random numbers. 
      Random rnd = new Random(); 

      for (int i = 0; i < rnd.Next(5); i++) 
       GridItems.Add(rnd.Next(100)); 
     } 
    } 
} 
관련 문제