Click here to Skip to main content
15,672,482 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to merge cells in Excel using C# Pin
Richard MacCutchan12-Aug-21 21:35
mveRichard MacCutchan12-Aug-21 21:35 
GeneralRe: How to merge cells in Excel using C# Pin
Ismael Oliveira 202113-Aug-21 13:45
Ismael Oliveira 202113-Aug-21 13:45 
GeneralRe: How to merge cells in Excel using C# Pin
Richard MacCutchan13-Aug-21 21:44
mveRichard MacCutchan13-Aug-21 21:44 
GeneralRe: How to merge cells in Excel using C# Pin
Ismael Oliveira 202114-Aug-21 12:46
Ismael Oliveira 202114-Aug-21 12:46 
GeneralRe: How to merge cells in Excel using C# Pin
Richard MacCutchan14-Aug-21 21:09
mveRichard MacCutchan14-Aug-21 21:09 
QuestionPassing a variable from an string to a For loop Pin
Alex Dunlop11-Aug-21 23:55
Alex Dunlop11-Aug-21 23:55 
AnswerRe: Passing a variable from an string to a For loop Pin
Pete O'Hanlon12-Aug-21 2:28
subeditorPete O'Hanlon12-Aug-21 2:28 
GeneralRe: Passing a variable from an string to a For loop Pin
harold aptroot12-Aug-21 2:42
harold aptroot12-Aug-21 2:42 
AnswerRe: Passing a variable from an string to a For loop Pin
Richard Deeming12-Aug-21 2:48
mveRichard Deeming12-Aug-21 2:48 
AnswerRe: Passing a variable from an string to a For loop Pin
jsc4212-Aug-21 3:08
professionaljsc4212-Aug-21 3:08 
AnswerRe: Passing a variable from an string to a For loop Pin
Dave Kreskowiak12-Aug-21 3:32
mveDave Kreskowiak12-Aug-21 3:32 
AnswerRe: Passing a variable from an string to a For loop Pin
Gerry Schmitz12-Aug-21 4:13
mveGerry Schmitz12-Aug-21 4:13 
AnswerRe: Passing a variable from an string to a For loop Pin
OriginalGriff12-Aug-21 4:20
mvaOriginalGriff12-Aug-21 4:20 
GeneralRe: Passing a variable from an string to a For loop Pin
Alex Dunlop12-Aug-21 6:16
Alex Dunlop12-Aug-21 6:16 
GeneralRe: Passing a variable from an string to a For loop Pin
OriginalGriff12-Aug-21 6:36
mvaOriginalGriff12-Aug-21 6:36 
GeneralRe: Passing a variable from an string to a For loop Pin
Alex Dunlop12-Aug-21 8:55
Alex Dunlop12-Aug-21 8:55 
GeneralRe: Passing a variable from an string to a For loop Pin
OriginalGriff12-Aug-21 22:49
mvaOriginalGriff12-Aug-21 22:49 
GeneralRe: Passing a variable from an string to a For loop Pin
Alex Dunlop13-Aug-21 7:26
Alex Dunlop13-Aug-21 7:26 
GeneralRe: Passing a variable from an string to a For loop Pin
Alex Dunlop13-Aug-21 7:31
Alex Dunlop13-Aug-21 7:31 
GeneralRe: Passing a variable from an string to a For loop Pin
OriginalGriff14-Aug-21 1:35
mvaOriginalGriff14-Aug-21 1:35 
GeneralRe: Passing a variable from an string to a For loop Pin
Alex Dunlop13-Aug-21 7:39
Alex Dunlop13-Aug-21 7:39 
The class I wrote for this purpose:
C#
class ActivityTimeSum
    {
        public string settings { get; set; }
        public string dataTableName { get; set; }
        public DataTable selectDT { get; set; }
        public CheckEdit checkBox1 { get; set; }
        public CheckEdit checkBox2 { get; set; }
        public CheckEdit checkBox3 { get; set; }
        public CheckEdit checkBox4 { get; set; }

        Dictionary<string, int> myDic = new Dictionary<string, int>();
        List<string> keys = new List<string>();
        List<int> values = new List<int>();
        List<CheckEdit> checkBoxes = new List<CheckEdit>();
        List<string> selectedCheckBox = new List<string>();

        public Dictionary<string, int> CalculateTime()
        {
            checkBoxes.Add(checkBox1);
            checkBoxes.Add(checkBox2);
            checkBoxes.Add(checkBox3);
            checkBoxes.Add(checkBox4);

            foreach (var c in checkBoxes)
            {
                if (c.Checked)
                {
                    selectedCheckBox.Add(c.Tag.ToString());
                }
            }
            for (int i = 0; i < selectDT.Rows.Count; i++)
            {
                switch (selectedCheckBox.Count)
                {
                    case 1:
                        keys.Add(selectDT.Rows[i][Int32.Parse(selectedCheckBox[0])].ToString());
                        break;
                    case 2:
                        keys.Add(string.Join(", ", selectDT.Rows[i][Int32.Parse(selectedCheckBox[0])].ToString(), 
                            selectDT.Rows[i][Int32.Parse(selectedCheckBox[1])].ToString()));
                        break;
                    case 3:
                        keys.Add(string.Join(", ", selectDT.Rows[i][Int32.Parse(selectedCheckBox[0])].ToString(),
                            selectDT.Rows[i][Int32.Parse(selectedCheckBox[1])].ToString(), selectDT.Rows[i][Int32.Parse(selectedCheckBox[2])].ToString()));
                        break;
                    case 4:
                        keys.Add(string.Join(", ", selectDT.Rows[i][Int32.Parse(selectedCheckBox[0])].ToString(),
                            selectDT.Rows[i][Int32.Parse(selectedCheckBox[1])].ToString(), selectDT.Rows[i][Int32.Parse(selectedCheckBox[2])].ToString(),
                            selectDT.Rows[i][Int32.Parse(selectedCheckBox[3])].ToString()));
                        break;
                }
                values.Add(Int32.Parse(selectDT.Rows[i][11].ToString()));
            }

            for (int i = 0; i < selectDT.Rows.Count; i++)
            {
                if (myDic.ContainsKey(keys[i]))
                {
                    myDic[keys[i]] += values[i];
                }
                else
                {
                    myDic[keys[i]] = values [i];
                }
            }
            return myDic;


modified 13-Aug-21 13:50pm.

QuestionHow to split an string and remove extra spaces Pin
Alex Dunlop10-Aug-21 22:55
Alex Dunlop10-Aug-21 22:55 
AnswerRe: How to split an string and remove extra spaces Pin
Richard MacCutchan10-Aug-21 23:39
mveRichard MacCutchan10-Aug-21 23:39 
AnswerRe: How to split an string and remove extra spaces Pin
Pete O'Hanlon11-Aug-21 7:33
subeditorPete O'Hanlon11-Aug-21 7:33 
GeneralRe: How to split an string and remove extra spaces Pin
OriginalGriff11-Aug-21 7:58
mvaOriginalGriff11-Aug-21 7:58 

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.