Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert String Array Values Into DataGridView C#
    primarykey
    data
    text
    <p>I am developing a <strong>windows form application</strong> in <strong>C#</strong>. My Program will read the values from excel cells and insert the data into DataGridView to display the users. </p> <p>After I have read the excel files, I get the results in string arrays. How can I insert into DataGridView? </p> <pre><code>private void btnImport_Click(object sender, EventArgs e) { Microsoft.Office.Interop.Excel.Application ExcelObj = null; ExcelObj = new Microsoft.Office.Interop.Excel.Application(); if (ExcelObj != null) { if (tbxFileDirectory.Text != "") { Workbook workbook = ExcelObj.Workbooks.Open( openFD.FileName, 0, true, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true); Sheets sheets = workbook.Worksheets; //Get excel sheet number Worksheet worksheet = (Worksheet)sheets.get_Item(1); for (int i = 6; i &lt;= worksheet.UsedRange.Rows.Count; i++) { Range range = worksheet.get_Range("A" + i.ToString(), "K" + i.ToString()); Array myvalues = (Array)range.Cells.Value; string[] strArray = ConvertToStringArray(myvalues); //INSERT INTO DATAGRIDVIEW } MessageBox.Show("File was imported successfully"); } else { MessageBox.Show("Please select the file to import."); } } else { MessageBox.Show("ERROR: EXCEL couldn't be started!"); } } </code></pre> <p>My DataGrid has 4 columns, ProductID, ProductName, Price, &amp; Qty. I want to insert these values, strArray[0], strArray[1], strArray[9] &amp; strArray[10] in each of the column. How can I do this? Any help will be much appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload