Click here to Skip to main content
15,886,919 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
QuestionIs a separate view model relevant for Blazor server side given that we can test the whole component with bUnit? Pin
Mr Yossu25-Feb-24 5:38
Mr Yossu25-Feb-24 5:38 
AnswerRe: Is a separate view model relevant for Blazor server side given that we can test the whole component with bUnit? Pin
Gerry Schmitz25-Feb-24 10:06
mveGerry Schmitz25-Feb-24 10:06 
GeneralRe: Is a separate view model relevant for Blazor server side given that we can test the whole component with bUnit? Pin
Mr Yossu26-Feb-24 3:37
Mr Yossu26-Feb-24 3:37 
GeneralRe: Is a separate view model relevant for Blazor server side given that we can test the whole component with bUnit? Pin
Gerry Schmitz26-Feb-24 4:43
mveGerry Schmitz26-Feb-24 4:43 
GeneralRe: Is a separate view model relevant for Blazor server side given that we can test the whole component with bUnit? Pin
Mr Yossu26-Feb-24 4:49
Mr Yossu26-Feb-24 4:49 
AnswerRe: Is a separate view model relevant for Blazor server side given that we can test the whole component with bUnit? Pin
jschell26-Feb-24 12:32
jschell26-Feb-24 12:32 
AnswerRe: Oh my goodness! Pin
Dave Kreskowiak24-Feb-24 4:38
mveDave Kreskowiak24-Feb-24 4:38 
GeneralRe: Oh my goodness! Pin
Gerry Schmitz24-Feb-24 4:42
mveGerry Schmitz24-Feb-24 4:42 
GeneralRe: Oh my goodness! Pin
Dave Kreskowiak24-Feb-24 5:53
mveDave Kreskowiak24-Feb-24 5:53 
QuestionC# How to populate datagridview from a separate combobox selection Pin
mourad barsoum22-Feb-24 12:57
mourad barsoum22-Feb-24 12:57 
I am familiar with Excel VBA but new to C# and Visual Basicvisula Studio. I have an Excel file (.xlsm) with several sheets. Using ExcelDataReader, I managed to build a solution to show all sheet names in a combobox control.

I need help in how can I import the selected sheet content in combobox (cboSheet) to the datagridview1
C#
using ExcelDataReader;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.IO;
    using System.Data.SqlClient;
    
    namespace ReadandImportsheet1
    {
    public partial class Form1 : Form
    {
        
        
        private readonly object con;
        

        public object Break { get; private set; }

        public Form1()
        {
            InitializeComponent();
        }

        public Form1(object con)
        {
            this.con = con;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog fil = new OpenFileDialog();
            fil.ShowDialog();
            string path = fil.FileName.ToString();
            ExcelFileReader(path);
        }
        public void ExcelFileReader(string path)
        {
            var stream = File.Open(path, FileMode.Open, FileAccess.Read);
            var reader = ExcelReaderFactory.CreateReader(stream);
            var result = reader.AsDataSet();
            var tables = result.Tables;
            foreach (DataTable table in tables)
            {
                cboSheet.Items.Add(table.TableName);
            }
            //var shname = cboSheet.SelectedValue;
            //string table_name = cboSheet.Text;
        }

        private void cboSheet_SelectedIndexChanged(object sender, EventArgs e)
        {
            string table_name = cboSheet.Text;
            SqlConnection Con = new SqlConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = path; Extended Properties = "Excel 8.0; HDR = YES";");
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from " + table_name + " ", con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
            dataGridView1.DataBind();

            con.Close();
        }
    }
}
I am using Win 11 and Visual Studio 2019 with ExcelDataReader and Exceldatareader.Dataset

Any help in coding will be extremely appreciated as I am new to C# coding and can not get sheet contents into the datagridview control.

modified 23-Feb-24 1:23am.

AnswerRe: C# How to populate datagridview from a separate combobox selection Pin
Gerry Schmitz23-Feb-24 7:40
mveGerry Schmitz23-Feb-24 7:40 
AnswerRe: C# How to populate datagridview from a separate combobox selection Pin
Vrend Top11-Apr-24 1:13
Vrend Top11-Apr-24 1:13 
GeneralRe: C# How to populate datagridview from a separate combobox selection Pin
RedDk11-Apr-24 8:11
RedDk11-Apr-24 8:11 
QuestionTop 100 algorithm Pin
mike741120-Jan-24 10:39
mike741120-Jan-24 10:39 
AnswerRe: Top 100 algorithm Pin
Richard MacCutchan29-Jan-24 4:21
mveRichard MacCutchan29-Jan-24 4:21 
AnswerRe: Top 100 algorithm Pin
Pete O'Hanlon29-Jan-24 4:34
mvePete O'Hanlon29-Jan-24 4:34 
Questionuser data system for a web-based e-mail service Pin
mike741115-Jan-24 2:04
mike741115-Jan-24 2:04 
AnswerRe: user data system for a web-based e-mail service Pin
Richard MacCutchan15-Jan-24 2:25
mveRichard MacCutchan15-Jan-24 2:25 
AnswerRe: user data system for a web-based e-mail service Pin
jschell15-Jan-24 4:12
jschell15-Jan-24 4:12 
AnswerRe: user data system for a web-based e-mail service Pin
Eddy Vluggen16-Jan-24 5:00
professionalEddy Vluggen16-Jan-24 5:00 
GeneralRe: user data system for a web-based e-mail service Pin
jschell17-Jan-24 4:24
jschell17-Jan-24 4:24 
GeneralRe: user data system for a web-based e-mail service Pin
Richard MacCutchan17-Jan-24 5:33
mveRichard MacCutchan17-Jan-24 5:33 
GeneralRe: user data system for a web-based e-mail service Pin
RedDk17-Jan-24 8:24
RedDk17-Jan-24 8:24 
GeneralRe: user data system for a web-based e-mail service Pin
Richard MacCutchan17-Jan-24 22:55
mveRichard MacCutchan17-Jan-24 22:55 
GeneralRe: user data system for a web-based e-mail service Pin
RedDk18-Jan-24 8:08
RedDk18-Jan-24 8:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.