Как вы можете видеть на рисунке ниже, в середине DataGridView вы можете увидеть все доступные виды рыб и их факторы, например;Коэффициент рыболова = 1,22.
Если пользователь выбирает рыболов в поле со списком и вводит, сколько он поймал, например, пользователь выбирает рыболов и вводит 5 в сумму, то какой самый простой способ умножить комбинированный список 1 на коэффициент? 1,22? и отобразить его в DataGridView справа?
Коэффициент должен меняться в зависимости от того, что пользователь выбирает в поле со списком.
Слева от изображения, которое я включил, у вас есть опциячтобы выбрать, какую лодку вы хотите просмотреть, когда я переключаю лодки, 4 вида рыб из предыдущей лодки отображаются в текущей лодке, я не знаю, как их разделить
Как я инициализировал:
List<Fleet> boatList = new List<Fleet>();
List<Fish> fishList = new List<Fish>();
DataTable dt = new DataTable();
DataTable dt2 = new DataTable();
DataTable dt3 = new DataTable();
private Fleet currentBoat;
private int boats = 0;
private Fish currentFish;
private int fishes = 0;
public Form1()
{
InitializeComponent();
}
//Initialises
string[] Species = new string[9] { "Angler", "Cod", "Haddock", "Hake", "Horse Mackerel", "Witches", "Plaice", "Skate and Rays", "Whiting" };
decimal[] Tonnes = new decimal[9] { 5, 3, 4, 1, 0.5m, 3, 8, 1.8m, 7 };
decimal[] Factor = new decimal[9] { 1.22m, 1.17m, 1.17m, 1.11m, 1.08m, 1.06m, 1.05m, 1.13m, 1.18m };
int[] Kilograms = new int[9] { 5000, 3000, 4000, 1000, 500, 3000, 8000, 1800, 7000 };
string[] weightVar = new string[2] { "KG", "T" };
int[] FishAmount = new int[4];
decimal[] Fished = new decimal[4];
Что находится внутри моей form_load ():
private void Form1_Load(object sender, EventArgs e)
{
LogoPictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
var species = new List<object>
{
new Fish(Species[0], Kilograms[0],0).GetSpecies(),
new Fish(Species[1], Kilograms[1],0).GetSpecies(),
new Fish(Species[2], Kilograms[2],0).GetSpecies(),
new Fish(Species[3], Kilograms[3],0).GetSpecies(),
new Fish(Species[4], Kilograms[4],0).GetSpecies(),
new Fish(Species[5], Kilograms[5],0).GetSpecies(),
new Fish(Species[6], Kilograms[6],0).GetSpecies(),
new Fish(Species[7], Kilograms[7],0).GetSpecies(),
new Fish(Species[8], Kilograms[8],0).GetSpecies()
};
Catch1ComboBox.DataSource = new BindingList<object>(species);
Catch2ComboBox.DataSource = new BindingList<object>(species);
Catch3ComboBox.DataSource = new BindingList<object>(species);
Catch4ComboBox.DataSource = new BindingList<object>(species);
Catch1ComboBox.SelectedIndex = -1;
Catch2ComboBox.SelectedIndex = -1;
Catch3ComboBox.SelectedIndex = -1;
Catch4ComboBox.SelectedIndex = -1;
}
Как я заполняю DataGridView ниже:
private void BoatSubmitButton_Click(object sender, EventArgs e)
{
if (Catch1ComboBox.SelectedIndex == 1)
{
}
//Boat
string licenseVariable = BoatLicenseTextBox.Text;
string intVariable = MaximumLoadTextBox.Text;
//Fishes
FishAmount[0] = int.Parse(NumericAmount1.Text);
FishAmount[1] = int.Parse(NumericAmount2.Text);
FishAmount[2] = int.Parse(NumericAmount3.Text);
FishAmount[3] = int.Parse(NumericAmount4.Text);
for (int i = 0; i < Fished.Length; i++)
{
Fished[i] = FishAmount[i] * Factor[i];
}
//Error Checking
if (BoatNameTextBox.Text == "" ||
BoatLicenseTextBox.Text == "" ||
MaximumLoadTextBox.Text == "")
{
MessageBox.Show("Please Input Name", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (!Check(Catch1ComboBox, NumericAmount1) || !Check(Catch2ComboBox, NumericAmount2) ||
!Check(Catch3ComboBox, NumericAmount3) || !Check(Catch4ComboBox, NumericAmount4))
{
MessageBox.Show("Please Input Amount Of Fish Caught", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if ((Catch1ComboBox.SelectedIndex == -1) || (Catch2ComboBox.SelectedIndex == -1 ) ||
(Catch3ComboBox.SelectedIndex == -1) || (Catch4ComboBox.SelectedIndex == -1))
{
MessageBox.Show("Please Select A Fish Specie", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
//Displays User Input Into DataGrid Boxes
else
{
boatList.Add(new Fleet(BoatNameTextBox.Text, licenseVariable, intVariable));
fishList.Add(new Fish(Catch1ComboBox.SelectedItem.ToString(), Fished[0], Kilograms[0]));
fishList.Add(new Fish(Catch2ComboBox.SelectedItem.ToString(), Fished[1], Kilograms[1]));
fishList.Add(new Fish(Catch3ComboBox.SelectedItem.ToString(), Fished[2], Kilograms[2]));
fishList.Add(new Fish(Catch4ComboBox.SelectedItem.ToString(), Fished[3], Kilograms[3]));
currentBoat = boatList[boats];
currentFish = fishList[fishes];
//Reset Boat Boxes
BoatNameTextBox.Text = "";
BoatLicenseTextBox.Text = "";
MaximumLoadTextBox.Text = "";
//Reset Combo Boxes
Catch1ComboBox.SelectedIndex = -1;
Catch2ComboBox.SelectedIndex = -1;
Catch3ComboBox.SelectedIndex = -1;
Catch4ComboBox.SelectedIndex = -1;
//Reset Numeric Value Boxes
NumericAmount1.Value = 0;
NumericAmount2.Value = 0;
NumericAmount3.Value = 0;
NumericAmount4.Value = 0;
//Add-On To Boat List
boats++;
//Add Boat To Combo Box
var last = boatList.Last(); // using System.Linq;
BoatSelector.Items.Add(last.GetboatName() + " - " + last.GetboatLicense());
BoatSelector.SelectedIndex +=1;
}
}
private void BoatSelector_SelectedIndexChanged(object sender, EventArgs e)
{
for(int i = 0; i < boatList.Count; i++)
{
if (BoatSelector.SelectedIndex == i)
{
dt2.Rows.Clear();
dt3.Rows.Clear();
dt2.Rows.Add(new object[] { boatList[i].GetboatName(), boatList[i].GetboatLicense(), boatList[i].GetmaximumLoad() });
dt3.Rows.Add(new object[] { fishList[0].GetSpecies(), fishList[0].GetFished() + weightVar[0], fishList[i].GetQouta()});
dt3.Rows.Add(new object[] { fishList[1].GetSpecies(), fishList[1].GetFished() + weightVar[0], fishList[i].GetQouta()});
dt3.Rows.Add(new object[] { fishList[2].GetSpecies(), fishList[2].GetFished() + weightVar[0], fishList[i].GetQouta()});
dt3.Rows.Add(new object[] { fishList[3].GetSpecies(), fishList[3].GetFished() + weightVar[0], fishList[i].GetQouta()});
}
}
}