0 / 0 / 0
Регистрация: 11.10.2020
Сообщений: 5

Windows forms вывод в datagridview

26.10.2020, 12:47. Показов 1249. Ответов 0

Студворк — интернет-сервис помощи студентам
Всем здравствуйте, помогите допилить код, чтобы результаты функции выводились в datagridview.
Возможно есть другой способ вывода данных в таблицу?

Function.h
C++
1
2
3
4
5
6
7
#pragma once
#include <iostream>
#include <clocale>
#include <iomanip>
#include <math.h>
 
double Taylor(double x, double e, int& n);
Function.cpp
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "Function.h"
double Taylor(double x, double e, int& n)
{
    double sum = 0;
    double an = 1;
    n = 1;
    do
    {
        sum += an;
        n += 1;
        an *= (-1) * (pow(x, n) / n);
    } while (e <= fabs(an));
    return sum;
}
MyForm3.h
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#pragma once
#include "Function.h"
 
 
 
namespace kursovaya {
 
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
 
    /// <summary>
    /// Сводка для MyForm3
    /// </summary>
    public ref class MyForm3 : public System::Windows::Forms::Form
    {
    public:
        MyForm3(void)
        {
            InitializeComponent();
            //
            //TODO: добавьте код конструктора
            //
        }
 
    protected:
        /// <summary>
        /// Освободить все используемые ресурсы.
        /// </summary>
        ~MyForm3()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Label^ label1;
    protected:
    private: System::Windows::Forms::PictureBox^ pictureBox1;
    private: System::Windows::Forms::Label^ label2;
    private: System::Windows::Forms::Label^ label3;
    private: System::Windows::Forms::TextBox^ textBox1;
    private: System::Windows::Forms::Label^ label4;
    private: System::Windows::Forms::Label^ label5;
 
    private: System::Windows::Forms::Label^ label6;
    private: System::Windows::Forms::TextBox^ textBox2;
    private: System::Windows::Forms::TextBox^ textBox3;
    private: System::Windows::Forms::Label^ label7;
    private: System::Windows::Forms::TextBox^ textBox4;
    private: System::Windows::Forms::DataGridView^ dataGridView1;
 
 
 
    private: System::Windows::Forms::Button^ button1;
 
 
 
    private: System::ComponentModel::BackgroundWorker^ backgroundWorker1;
    private: System::Windows::Forms::DataGridViewTextBoxColumn^ Column1;
    private: System::Windows::Forms::DataGridViewTextBoxColumn^ Column2;
    private: System::Windows::Forms::DataGridViewTextBoxColumn^ Column3;
 
 
 
 
 
 
 
    private:
        /// <summary>
        /// Обязательная переменная конструктора.
        /// </summary>
        System::ComponentModel::Container ^components;
 
#pragma region Windows Form Designer generated code
        /// <summary>
        /// Требуемый метод для поддержки конструктора — не изменяйте 
        /// содержимое этого метода с помощью редактора кода.
        /// </summary>
        void InitializeComponent(void)
        {
            System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(MyForm3::typeid));
            this->label1 = (gcnew System::Windows::Forms::Label());
            this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
            this->label2 = (gcnew System::Windows::Forms::Label());
            this->label3 = (gcnew System::Windows::Forms::Label());
            this->textBox1 = (gcnew System::Windows::Forms::TextBox());
            this->label4 = (gcnew System::Windows::Forms::Label());
            this->label5 = (gcnew System::Windows::Forms::Label());
            this->label6 = (gcnew System::Windows::Forms::Label());
            this->textBox2 = (gcnew System::Windows::Forms::TextBox());
            this->textBox3 = (gcnew System::Windows::Forms::TextBox());
            this->label7 = (gcnew System::Windows::Forms::Label());
            this->textBox4 = (gcnew System::Windows::Forms::TextBox());
            this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->backgroundWorker1 = (gcnew System::ComponentModel::BackgroundWorker());
            this->Column1 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
            this->Column2 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
            this->Column3 = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->BeginInit();
            this->SuspendLayout();
            // 
            // label1
            // 
            this->label1->AutoSize = true;
            this->label1->Font = (gcnew System::Drawing::Font(L"Times New Roman", 15.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(204)));
            this->label1->Location = System::Drawing::Point(236, 18);
            this->label1->Name = L"label1";
            this->label1->Size = System::Drawing::Size(192, 23);
            this->label1->TabIndex = 0;
            this->label1->Text = L"Организация циклов";
            // 
            // pictureBox1
            // 
            this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"pictureBox1.Image")));
            this->pictureBox1->Location = System::Drawing::Point(29, 44);
            this->pictureBox1->Name = L"pictureBox1";
            this->pictureBox1->Size = System::Drawing::Size(642, 108);
            this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
            this->pictureBox1->TabIndex = 1;
            this->pictureBox1->TabStop = false;
            // 
            // label2
            // 
            this->label2->AutoSize = true;
            this->label2->Font = (gcnew System::Drawing::Font(L"Times New Roman", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(204)));
            this->label2->Location = System::Drawing::Point(25, 164);
            this->label2->Name = L"label2";
            this->label2->Size = System::Drawing::Size(29, 27);
            this->label2->TabIndex = 2;
            this->label2->Text = L"Х";
            // 
            // label3
            // 
            this->label3->AutoSize = true;
            this->label3->BackColor = System::Drawing::SystemColors::ButtonHighlight;
            this->label3->Font = (gcnew System::Drawing::Font(L"Times New Roman", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(204)));
            this->label3->Location = System::Drawing::Point(51, 175);
            this->label3->Name = L"label3";
            this->label3->Size = System::Drawing::Size(78, 19);
            this->label3->TabIndex = 3;
            this->label3->Text = L"начальное";
            // 
            // textBox1
            // 
            this->textBox1->Location = System::Drawing::Point(134, 168);
            this->textBox1->Name = L"textBox1";
            this->textBox1->Size = System::Drawing::Size(79, 20);
            this->textBox1->TabIndex = 4;
            // 
            // label4
            // 
            this->label4->AutoSize = true;
            this->label4->Font = (gcnew System::Drawing::Font(L"Times New Roman", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(204)));
            this->label4->Location = System::Drawing::Point(219, 164);
            this->label4->Name = L"label4";
            this->label4->Size = System::Drawing::Size(29, 27);
            this->label4->TabIndex = 5;
            this->label4->Text = L"Х";
            // 
            // label5
            // 
            this->label5->AutoSize = true;
            this->label5->BackColor = System::Drawing::SystemColors::ButtonHighlight;
            this->label5->Font = (gcnew System::Drawing::Font(L"Times New Roman", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(204)));
            this->label5->Location = System::Drawing::Point(245, 175);
            this->label5->Name = L"label5";
            this->label5->Size = System::Drawing::Size(71, 19);
            this->label5->TabIndex = 6;
            this->label5->Text = L"конечное";
            // 
            // label6
            // 
            this->label6->AutoSize = true;
            this->label6->Font = (gcnew System::Drawing::Font(L"Times New Roman", 18, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(204)));
            this->label6->Location = System::Drawing::Point(407, 164);
            this->label6->Name = L"label6";
            this->label6->Size = System::Drawing::Size(36, 27);
            this->label6->TabIndex = 8;
            this->label6->Text = L"dx";
            // 
            // textBox2
            // 
            this->textBox2->Location = System::Drawing::Point(322, 168);
            this->textBox2->Name = L"textBox2";
            this->textBox2->Size = System::Drawing::Size(79, 20);
            this->textBox2->TabIndex = 9;
            // 
            // textBox3
            // 
            this->textBox3->Location = System::Drawing::Point(449, 168);
            this->textBox3->Name = L"textBox3";
            this->textBox3->Size = System::Drawing::Size(79, 20);
            this->textBox3->TabIndex = 10;
            // 
            // label7
            // 
            this->label7->AutoSize = true;
            this->label7->Font = (gcnew System::Drawing::Font(L"Times New Roman", 20.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(204)));
            this->label7->Location = System::Drawing::Point(541, 160);
            this->label7->Name = L"label7";
            this->label7->Size = System::Drawing::Size(25, 31);
            this->label7->TabIndex = 11;
            this->label7->Text = L"ε";
            // 
            // textBox4
            // 
            this->textBox4->Location = System::Drawing::Point(583, 168);
            this->textBox4->Name = L"textBox4";
            this->textBox4->Size = System::Drawing::Size(88, 20);
            this->textBox4->TabIndex = 12;
            // 
            // dataGridView1
            // 
            this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
            this->dataGridView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^  >(3) {
                this->Column1,
                    this->Column2, this->Column3
            });
            this->dataGridView1->Location = System::Drawing::Point(29, 241);
            this->dataGridView1->Name = L"dataGridView1";
            this->dataGridView1->Size = System::Drawing::Size(642, 185);
            this->dataGridView1->TabIndex = 13;
            // 
            // button1
            // 
            this->button1->Font = (gcnew System::Drawing::Font(L"Times New Roman", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(204)));
            this->button1->Location = System::Drawing::Point(261, 202);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(181, 26);
            this->button1->TabIndex = 14;
            this->button1->Text = L"Расчитать";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &MyForm3::button1_Click);
            // 
            // Column1
            // 
            this->Column1->HeaderText = L"текущее значение x ";
            this->Column1->Name = L"Column1";
            this->Column1->Width = 200;
            // 
            // Column2
            // 
            this->Column2->HeaderText = L"текущее значение суммы";
            this->Column2->Name = L"Column2";
            this->Column2->Width = 200;
            // 
            // Column3
            // 
            this->Column3->HeaderText = L"счётчик итерации";
            this->Column3->Name = L"Column3";
            this->Column3->Width = 200;
            // 
            // MyForm3
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->BackColor = System::Drawing::SystemColors::ButtonHighlight;
            this->ClientSize = System::Drawing::Size(697, 454);
            this->Controls->Add(this->button1);
            this->Controls->Add(this->dataGridView1);
            this->Controls->Add(this->textBox4);
            this->Controls->Add(this->label7);
            this->Controls->Add(this->textBox3);
            this->Controls->Add(this->textBox2);
            this->Controls->Add(this->label6);
            this->Controls->Add(this->label4);
            this->Controls->Add(this->label5);
            this->Controls->Add(this->textBox1);
            this->Controls->Add(this->label2);
            this->Controls->Add(this->label3);
            this->Controls->Add(this->pictureBox1);
            this->Controls->Add(this->label1);
            this->Name = L"MyForm3";
            this->Text = L"Задание 3";
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->EndInit();
            this->ResumeLayout(false);
            this->PerformLayout();
 
        }
#pragma endregion
    
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    double xn, xk, dx, ep;
    int n;
    xn= System::Convert::ToDouble(textBox1->Text);
    xk = System::Convert::ToDouble(textBox2->Text);
    dx = System::Convert::ToDouble(textBox3->Text);
    ep = System::Convert::ToDouble(textBox4->Text); //Taylor(xn, ep, n) dataGridView1->Rows->Add()
    for (int i = 1; xn < xk; i++) {
        dataGridView1->Rows[i]->Cells[0]->Value = Convert::ToString(xn);
        dataGridView1->Rows[i]->Cells[1]->Value = Convert::ToString(Taylor(xn, ep, n));
        dataGridView1->Rows[i]->Cells[2]->Value = Convert::ToString(n);
        xn = xn + dx;
    }
}
};
}
0
IT_Exp
Эксперт
34794 / 4073 / 2104
Регистрация: 17.06.2006
Сообщений: 32,602
Блог
26.10.2020, 12:47
Ответы с готовыми решениями:

Вывод таблицы Windows Forms Application
Доброго времени суток. Использую VS 2008, проект Windows Forms Application. В каком элементе можно вывести таблицу, т.е....

Исправить код в Windows Forms: вывод бинарного файла в DataGridView
пожалуйста, кто может писать этот код в более понятном виде! тут очен странно написан, пожалуйсто помоч :rose: int row2 = 0; ...

работа с dataGridView в windows forms
здравствуйте! подскажите пожалуйста ,как сделать так, чтобы при изменении значения в ячейке датагрид изменения вносились и в массив...

0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
BasicMan
Эксперт
29316 / 5623 / 2384
Регистрация: 17.02.2009
Сообщений: 30,364
Блог
26.10.2020, 12:47
Помогаю со студенческими работами здесь

Windows Forms DataGridView спрятать столбец
Здравствуйте! Подскажите пожалуйста, можно ли спрятать столбец состояния DataGridView: чтобы в результате DataGridView выглядел...

Асинхронный запуск функций для DataGridView в Windows Forms
Форумчане, прошу вас подсказать, возможно ли асинхронно выполнить некоторую функцию для каждой строки элемента DataGridView? Функция...

Отображение данных из MySQL в Windows Forms средствами DataGridView
Доброго времени суток! Есть небольшая база в MySQL. При добавлении ее к форме Windows Forms (с#) в Visual Studio средствами DataGridView...

Привязка данных к элементу управления DataGridView в Windows Forms
Здравствуйте, есть форма с двумя DataGridView. Сделал по этому примеру: http://msdn.microsoft.com/ru-ru/library/fbk67b6z.aspx , но там...

Как удалить и изменить данные в базе sqlite через DataGridView (Windows Forms)?
Проблема в следующем: пишу на visual studio 2015, создаю базу sqlite через &quot;Server Explorer -- Data connections -- Add connection&quot; по...


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

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

Новые блоги и статьи
Оттенки серого
Argus19 18.03.2026
Оттенки серого Нашёл в интернете 3 прекрасных модуля: Модуль класса открытия диалога открытия/ сохранения файла на Win32 API; Модуль класса быстрого перекодирования цветного изображения в оттенки. . .
SDL3 для Desktop (MinGW): Рисуем цветные прямоугольники с помощью рисовальщика SDL3 на Си и C++
8Observer8 17.03.2026
Содержание блога Финальные проекты на Си и на C++: finish-rectangles-sdl3-c. zip finish-rectangles-sdl3-cpp. zip
Символические и жёсткие ссылки в Linux.
algri14 15.03.2026
Существует два типа ссылок — символические и жёсткие. Ссылка в Linux — это запись в каталоге, которая может указывать либо на inode «файла-ИСТОЧНИКА», тогда это будет «жёсткая ссылка» (hard link),. . .
[Owen Logic] Поддержание уровня воды в резервуаре количеством включённых насосов: моделирование и выбор регулятора
ФедосеевПавел 14.03.2026
Поддержание уровня воды в резервуаре количеством включённых насосов: моделирование и выбор регулятора ВВЕДЕНИЕ Выполняя задание на управление насосной группой заполнения резервуара,. . .
делаю науч статью по влиянию грибов на сукцессию
anaschu 13.03.2026
прикрепляю статью
SDL3 для Desktop (MinGW): Создаём пустое окно с нуля для 2D-графики на SDL3, Си и C++
8Observer8 10.03.2026
Содержание блога Финальные проекты на Си и на C++: hello-sdl3-c. zip hello-sdl3-cpp. zip Результат:
Установка CMake и MinGW 13.1 для сборки С и C++ приложений из консоли и из Qt Creator в EXE
8Observer8 10.03.2026
Содержание блога MinGW - это коллекция инструментов для сборки приложений в EXE. CMake - это система сборки приложений. Здесь описаны базовые шаги для старта программирования с помощью CMake и. . .
Как дизайн сайта влияет на конверсию: 7 решений, которые реально повышают заявки
Neotwalker 08.03.2026
Многие до сих пор воспринимают дизайн сайта как “красивую оболочку”. На практике всё иначе: дизайн напрямую влияет на то, оставит человек заявку или уйдёт через несколько секунд. Даже если у вас. . .
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2026, CyberForum.ru