将数据(行)添加到WPF datagrid uisng C# [英] Add data(rows) to WPF datagrid uisng C#
本文介绍了将数据(行)添加到WPF datagrid uisng C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Team,
我在设计模式下创建了低于3列的WPF数据网格。我想在按钮点击事件中添加以下信息。
Sr.No =自动编号
MappingFileColumnNames =要从List对象中的一个项目填充(我在< list>
Department 中有员工列表这是一个带值的ComboBox (部门1,部门,部门3)
请帮助。
我有什么试过:
Hello Team,
I have created WPF datagrid with below 3 columns in design mode. I want to add below information on button click event.
Sr.No = AutoNumber
MappingFileColumnNames = To be filled from items from one of List object (I have list of employees in a <list>
Department This is a ComboBox with values (Dept 1, Dept , Dept 3)
Please Help.
What I have tried:
List<string> MappingFileColumnNames = new List<string>();
private void GetExcelSheetColumnNames(string FilePath, int SelectedSheet)
{
Microsoft.Office.Interop.Excel.Application XLApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook wkb = XLApp.Workbooks.Open(FilePath, 0, true);
Microsoft.Office.Interop.Excel.Worksheet wks = (Microsoft.Office.Interop.Excel.Worksheet)wkb.Worksheets.get_Item(SelectedSheet);
Microsoft.Office.Interop.Excel.Range DataRng = wks.UsedRange;
string strCellData = "";
int colCnt = 0;
for (colCnt = 1; colCnt <= DataRng.Columns.Count; colCnt++)
{
string strColumn = "";
strColumn = (string)(DataRng.Cells[1, colCnt] as Microsoft.Office.Interop.Excel.Range).Value2;
MappingFileColumnNames.Add(strColumn);
}
}
推荐答案
DataTable dt=new DataTable();
dt.columns.add("name");
DataRow dr=null;
for(int i=0;i<4:i++)
{
dr=dt.newrow();
dr["name"]="sai";
dt.rows.add(dr);
}
datagrid.itemsource=dt.defaultview;
这篇关于将数据(行)添加到WPF datagrid uisng C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文