4 / 4 / 3 Регистрация: 20.11.2013 Сообщений: 150 |
|
1 |
|
20.01.2017, 01:17. Показов 9843. Ответов 5
Привет, Работал работал в результате вот что появилось убрать не могу никак Ошибка такая Не удается неявно преобразовать тип «string» в «System.Windows.Forms.DataGridViewTextBoxColum n» Весь визуальный проект превратился кучу ошибок…. Что это может быть и как исправить?
__________________
0 |
5858 / 4735 / 2940 Регистрация: 20.04.2015 Сообщений: 8,361 |
|
20.01.2017, 01:28 |
2 |
Что это может быть и как исправить? Это обыкновенное именование столбца DataGridView как свойства формы, а именно «Name».
1 |
Администратор 15243 / 12282 / 4904 Регистрация: 17.03.2014 Сообщений: 24,882 Записей в блоге: 1 |
|
20.01.2017, 01:32 |
3 |
Сообщение было отмечено dripservice как решение Решениеdripservice, похоже ты назвал один из DataGridViewTextBoxColumn именем Name что создало путаницу со свойством Name базового класса. Дай колонке какое нибудь другое имя.
2 |
4 / 4 / 3 Регистрация: 20.11.2013 Сообщений: 150 |
|
20.01.2017, 02:09 [ТС] |
4 |
Так поняла назвать нужно именно колонку или в самой базе данных изменить? Я вообще попробовал удалить datagrid не помогло все равно(
0 |
Администратор 15243 / 12282 / 4904 Регистрация: 17.03.2014 Сообщений: 24,882 Записей в блоге: 1 |
|
20.01.2017, 02:13 |
5 |
dripservice, нужно дать переменной с типом DataGridViewTextBoxColumn другое имя. Базу данных трогать не надо.
0 |
4 / 4 / 3 Регистрация: 20.11.2013 Сообщений: 150 |
|
20.01.2017, 03:09 [ТС] |
6 |
Спасибо помогло только пришлось поменять в самом Designers, не понятно как и почему появилось…
0 |
The code that is causing the problem is
txtResult.Text = Convert.ToString(step3);
and it produces the error
Cannot implicitly convert type ‘string’ to
‘System.Windows.Forms.Label’
See this image:
lc.
112k20 gold badges157 silver badges185 bronze badges
asked Feb 5, 2016 at 2:22
5
Going by the image, it would appear you are not actually having this issue. Intellisense will often leave previous compilation errors hanging around until you attempt another compilation — this is most notable in your image because the blue line indicating en error is off and does not cover the entire line. Always build or rebuild your code before assuming an error is still occurring.
answered Feb 5, 2016 at 2:27
DavidDavid
10.3k1 gold badge26 silver badges40 bronze badges
i am currently writing a program that allows users to view multiple transparent images ontop of one another, they are able to toggle 6 different images on or off.
To explain how it works:
Image 1 is always the background (unless its toggled off in which case the next ‘on’ image is the background)
for example:
-
if image 1 is ON and image 2 is ON then image 2 uses image 1 as its parent.
-
if image 1 is ON, image 2 is OFF and image 3 is ON then image 3 will use Image 1 as its parent
etc
To achieve this i created an array — imageName[6]. When an image is turned on the corresponding element (e.g. image 1 = imageName[0]) says [image1].
Using this method i was hoping to create a control which would change the ‘parent’ of an image based on the example shown above.
I thought using the following code would work:
imageB.parent = imageName[0]
//This is just an example, the required answer would be imageB.parent = imageA
//I need to achieve this answer using the data in the array.
but i just get the error message listed in the title:
(Cannot implicitly convert type ‘string’ to ‘System.Windows.Forms.Control’ (CS0029) )
Could anyone help me with this problem? Im afraid im stumped.
Please note, my code is alot more complicated then this, the above just shows a small snippet of it rather then displaying all 776 lines of my code xD
UPDATE:
To summarise, i need to assign an images parent based on the name stored in part of my array (in this case [0] ie [image1]
The error im having makes this impossible,
Is there a way to solve this or am i just writing very bad code?
i am currently writing a program that allows users to view multiple transparent images ontop of one another, they are able to toggle 6 different images on or off.
To explain how it works:
Image 1 is always the background (unless its toggled off in which case the next ‘on’ image is the background)
for example:
-
if image 1 is ON and image 2 is ON then image 2 uses image 1 as its parent.
-
if image 1 is ON, image 2 is OFF and image 3 is ON then image 3 will use Image 1 as its parent
etc
To achieve this i created an array — imageName[6]. When an image is turned on the corresponding element (e.g. image 1 = imageName[0]) says [image1].
Using this method i was hoping to create a control which would change the ‘parent’ of an image based on the example shown above.
I thought using the following code would work:
imageB.parent = imageName[0]
//This is just an example, the required answer would be imageB.parent = imageA
//I need to achieve this answer using the data in the array.
but i just get the error message listed in the title:
(Cannot implicitly convert type ‘string’ to ‘System.Windows.Forms.Control’ (CS0029) )
Could anyone help me with this problem? Im afraid im stumped.
Please note, my code is alot more complicated then this, the above just shows a small snippet of it rather then displaying all 776 lines of my code xD
UPDATE:
To summarise, i need to assign an images parent based on the name stored in part of my array (in this case [0] ie [image1]
The error im having makes this impossible,
Is there a way to solve this or am i just writing very bad code?
Здраствуйте.
Начну с того что сразу скажу что исправление при помощи
throw new NotImplementedException();
которое предлагает VS Code не подойдёт тк при использовании combobox поментально кидает к ошибке…
Form1.cs:
using static SDM_Lab5.PasMove;
namespace SDM_Lab5
{
public partial class Form1 : Form
{
Aeroplane aero;
Train tr;
Avto av;
public Form1()
{
InitializeComponent();
}
PasMove pm;
Gorod[] towns;
string pathString = @"C:UsersMisteDesktopЗадания_СИ(шарп)ЛабораторныеЛР_5SDM_Lab5SDM_Lab5img";
private void Form1_Load(object sender, EventArgs e)
{
aero = new Aeroplane(); // создаем экземпляры классов с начальными значениями
tr = new Train();
av = new Avto();
towns = new Gorod[5]; // Задаем значения полей
towns[0] = new Gorod("Москва", 709, "Moscow.jpg");
towns[1] = new Gorod("Рим", 3016, "Rome.jpg");
towns[2] = new Gorod("Нью-Йорк", 6883, "New-york.jpg");
towns[3] = new Gorod("Токио", 7598, "Tokyo.jpg");
towns[4] = new Gorod("Лондон", 2818, "London.jpg");
// добавим поле Name из каждого объекта в выпадающий список
for (int i = 0; i < 5; i++)
{ comboBox1.Items.Add(towns[i].Name); }
}
int k;
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
k = comboBox1.SelectedIndex;
// выводим расстояние до нужного города
label1.Text = towns[k].ToString();
// выводим соответствующую картинку
pictureBox1.Image = Image.FromFile(pathString + "\" + towns[k].Url);
}
private void button1_Click(object sender, EventArgs e)
{
if (comboBox2.Text == "")
{ MessageBox.Show("Не выбран транспорт!"); return; }
Form2 frm2 = new Form2(pm);
frm2.ShowDialog();
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBox2.SelectedIndex)
{
case 0: pm = aero; break; // Ошибки здесь, у aero; tr; av
case 1: pm = tr; break;
case 2: pm = av; break;
}
}
private void button2_Click(object sender, EventArgs e)
{
if (comboBox1.Text == "" || comboBox2.Text == "")
{ MessageBox.Show("Не выбраны данные для расчета"); return; }
else
{
double g = pm.Time(towns[k].Rast);
double c = (pm.Equals(av)) ? pm.CostTrip(towns[k].Rast) : pm.CostTrip(g);
label1.Text = string.Format("Стоимость поездки на 1 человека {0:f2} (без учета прочих сборов)", c);
}
}
}
}
PasMove.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SDM_Lab5
{
public class PasMove
{
public virtual int CountPas { get; set; }
public virtual double Speed { get; set; }
public string Name { get; set; }
public double CostFuel { get; set; }
public double Rashod { get; set; }
public double Time(double s)
{ return s / Speed; }
public virtual double CostTrip(double t)
{ return t * Rashod * CostFuel / CountPas; }
public class Aeroplane
{
int countPas;
double speed;
public int CountPas
{
get { return countPas; }
set { if (value <= 300) countPas = value; }
}
public double Speed
{
get => speed;
set { if (value > 600 && value <= 900) speed = value; }
}
string Name;
double CostFuel;
double Rashod;
public Aeroplane()
{
Name = "Самолет";
CountPas = 280;
Speed = 800;
CostFuel = 37.2;
Rashod = 2600;
}
}
public class Train
{
int countPas;
double speed;
public int CountPas
{
get { return countPas; }
set { if (value <= 300) countPas = value; }
}
public double Speed
{
get => speed;
set { if (value > 600 && value <= 900) speed = value; }
}
string Name;
double CostFuel;
double Rashod;
public Train()
{
Name = "Поезд";
CountPas = 500;
Speed = 80;
CostFuel = 3.2;
Rashod = 1600;
}
}
public class Avto
{
int countPas;
double speed;
public int CountPas
{
get { return countPas; }
set { if (value <= 300) countPas = value; }
}
public double Speed
{
get => speed;
set { if (value > 600 && value <= 900) speed = value; }
}
double CostFuel;
double Rashod;
public virtual double CostTrip(double t) { return t / 100 * Rashod * CostFuel / CountPas;}
string Name;
public Avto()
{
Name = "Автомобиль";
CountPas = 3;
Speed = 110;
CostFuel = 3.2;
Rashod = 1600;
}
}
}
}
Извините что всё так конкретно и всё сразу не могу найти решение уже 2 дня