2014-04-10 46 views
0

我是編程新手。我目前在C#中使用WPF來從XML文件生成數據到數據網格(表格)。我正在使用MVVM格式。對於我的Model類,我將其命名爲PersonInfos,它包括「名字」,「姓氏」,「選擇」和「年齡」列。我想通過點擊「選擇」列中的複選框,根據用戶選擇的行創建一個txt文件。 TXT文件的格式顯示如下:如何以特定格式從數據網格創建txt文件?

e.g. 
P§Alexander§Jason§24§ 

P§ = It is the keyword for PersonInfos 
Alexander§ = Last Name 
Jason§ = First Name 
24§ = Age 

我會顯示下XAML我的WPF的代碼給一個更好的主意。

<syncfusion:GridTreeControl.Columns> 
       <syncfusion:GridTreeColumn MappingName="LastName" PercentWidth="3" /> 
       <syncfusion:GridTreeColumn MappingName="FirstName" PercentWidth="3" /> 
       <syncfusion:GridTreeColumn MappingName="Age" PercentWidth="2" /> 
       <syncfusion:GridTreeColumn MappingName="Select" PercentWidth="2"> 
        <syncfusion:GridTreeColumn.StyleInfo> 
         <syncfusion:GridDataStyleInfo 
           CellType="DataBoundTemplate" 
           CellItemTemplate="{StaticResource SelectCheckBoxTemplate}"/> 
        </syncfusion:GridTreeColumn.StyleInfo> 
       </syncfusion:GridTreeColumn>    
</syncfusion:GridTreeControl.Columns> 

謝謝你的時間!

回答

1

最簡單的方法是將一個屬性bool IncludeInExport添加到您的模型類(或派生模型類或部分模型類的類),並將其映射到網格的複選框。在導出時,您只需添加已檢查的行(包含IncludeInExport == true的PersonInfos集合項)。

相關問題