1 / 1 / 3
Регистрация: 15.12.2017
Сообщений: 134
1

Ошибка: "Не удалось привести типа объекта "System.Windows.Forms.TextBox" к типу "System.IConvertible".""

08.04.2018, 08:19. Показов 29037. Ответов 1
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
Программа выдает такой текст: "System.InvalidCastException: "Не удалось привести типа объекта "System.Windows.Forms.TextBox" к типу "System.IConvertible".""

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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;
 
namespace Lab7._2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            var column1 = new DataGridViewColumn();
            column1.HeaderText = "Значение аргумента";
            column1.Width = 100;
            column1.ReadOnly = true;
            column1.Name = "argument";
            column1.Frozen = true;
            column1.CellTemplate = new DataGridViewTextBoxCell();
            var column2 = new DataGridViewColumn();
            column2.HeaderText = "Значение функции";
            column2.Name = "function";
            column2.CellTemplate = new DataGridViewTextBoxCell();
            var column3 = new DataGridViewColumn();
            column3.HeaderText = "Значение функции класса Math";
            column3.Name = "MathFunction";
            column3.CellTemplate = new DataGridViewTextBoxCell();
            var column4 = new DataGridViewColumn();
            column4.HeaderText = "Разница двух значений";
            column4.Name = "Difference";
            column4.CellTemplate = new DataGridViewTextBoxCell();
            var column5 = new DataGridViewColumn();
            column5.HeaderText = "Количество просуммированных членов ряда";
            column5.Name = "quantity";
            column5.CellTemplate = new DataGridViewTextBoxCell();
            dataGridView1.Columns.Add(column1);
            dataGridView1.Columns.Add(column2);
            dataGridView1.Columns.Add(column3);
            dataGridView1.Columns.Add(column4);
            dataGridView1.Columns.Add(column5);
            dataGridView1.AllowUserToAddRows = false;
            int x1 = Convert.ToInt32(x1TextBox),
                x2 = Convert.ToInt32(x2TextBox),
                dx = Convert.ToInt32(StepTextBox),
                istart;
            double math, func;
            if ((x1 > -1) && (x2 <= 1))
                for (int i = x1; i < x2; i += dx)
                {
                    math = Math.Log(i + 1);
                    func = FuncionWithoutMath(x1, x2, dx);
                    istart = i;
                    dataGridView1.Rows.Add();
                    dataGridView1["argument", dataGridView1.Rows.Count - 1].Value = i;
                    dataGridView1["function", dataGridView1.Rows.Count - 1].Value = func;
                    dataGridView1["MathFunction", dataGridView1.Rows.Count - 1].Value = math;
                    dataGridView1["Difference", dataGridView1.Rows.Count - 1].Value = func - math;
                    dataGridView1["quantity", dataGridView1.Rows.Count - 1].Value = quantityFunc(istart, i, dx);
                }
            else
                Console.WriteLine("Одно из значений х выходит за рамки промежутка");
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView1.Columns.Count; j++)
                {
                    object o = dataGridView1[j, i].Value;
                }
            }
        }
        int FuncionWithoutMath(int start, int end, int step)
        {
            int function = start, n = start, m = 2;
            function += recursia(start+step, end, step, n, m);
            return function;
        }
        int recursia(int start, int end, int step, int n, int m)
        {
            int result = 0;
            if (start < end)
                result = n/m;
            n *= start; m++;
            return result;
        }
        int quantityFunc(int start, int end, int step)
        {
            return (end - start) / step + 1;
        }
    }
}
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
08.04.2018, 08:19
Ответы с готовыми решениями:

Ошибка "Не удалось привести тип объекта System.Windows.Forms.ComboBox к типу System.IConvertible"
Всем привет! Пытаюсь подключиться к COM-порту. Делал по примеру из интернета. При нажатии кнопки...

System.InvalidCastException: "Не удалось привести тип объекта "System.Windows.Forms.TableLayoutPanel" к типу "System.Win
namespace WindowsFormsApp1 { public partial class Form1 : Form { Game game; ...

Ошибка с заданием массива. Не удалось привести тип объекта "DataGridViewRow" к типу "System.IConvertible"
Не удалось привести тип объекта &quot;System.Windows.Forms.DataGridViewRow&quot; к типу...

Не удалось привести тип объекта "название проекта" к типу "System.IConvertible"."
вот код : var dataSource3 = new List&lt;Class1&gt;(); dataSource3.Add(new Class1() {...

Выдает ошибку - "Не удалось привести тип объекта "TheMaze.FormLevel1" к типу "System.Windows.Forms.Label"."
Ругается вот на эту строчку: ((Label)sender).Visible = false; Вот код: using System; using...

1
Эксперт .NET
17438 / 12830 / 3361
Регистрация: 17.09.2011
Сообщений: 21,108
08.04.2018, 09:02 2
Цитата Сообщение от Lololoshk Посмотреть сообщение
C#
1
2
3
int x1 = Convert.ToInt32(x1TextBox),
                x2 = Convert.ToInt32(x2TextBox),
                dx = Convert.ToInt32(StepTextBox)
Конвертировать в целое надо не текстовое поле, а текст, в нем прописанный (свойство Text).
0
08.04.2018, 09:02
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
08.04.2018, 09:02
Помогаю со студенческими работами здесь

System.InvalidCastException: "Не удалось привести тип объекта "System.Byte[]" к типу "System.Drawing.Bitmap"."
Ошибка System.InvalidCastException: &quot;Не удалось привести тип объекта &quot;System.Byte&quot; к типу...

Как исправить исключение "не удалось привести тип объекта TextBox к типу IConvertible"
private void button1_Click(object sender, EventArgs e) { int x =...

Не удалось привести тип объекта "System.Windows.Forms.RadioButton"
Здравствуйте! У меня возникло исключение на 22 строчке кода (текст исключения приведён в заголовке...

Не удалось привести тип объекта "System.Data.DataRowView" к типу "System.String"
Всем привет, как исправить то что написано в заголовке.

Не удалось привести тип объекта "System.Int32" к типу "System.String"
Доброго дня Всем!! Столкнулся с такой проблемой в Winforms С#, при нажатии на клавишу...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
2
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2023, CyberForum.ru