Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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);
            }
	    }
Posted
Updated 21-Aug-18 2:08am
Comments
Graeme_Grant 17-Aug-18 1:57am    
The code does not relate to the question. Please update the question, the code, or both...

1 solution

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;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900