there is a case which i download from projects table to combobox:
private void InsertStatus_Load(object sender, EventArgs e)
{
connection = new MySqlConnection();
connection.ConnectionString = "datasource=localhost;port=3306;username=root;password=";
connection.Open();
string selectQuery5 = "SELECT ID, PROJECT_NAME FROM projekt1.projects";
MySqlCommand command5 = new MySqlCommand(selectQuery5, connection);
MySqlDataReader reader5 = command5.ExecuteReader();
while (reader5.Read())
{
comboBox4.Items.Add(reader5.GetString("ID") + " " + reader5.GetString("PROJECT_NAME"));
}
connection.Close();
}
After downloading data to combobox it displays all ID's and PROJECT_NAME's
ID PROJECT_NAME
---- ------------
1 dasa
2 dsag3
3 S-BOX
. .
. .
. .
97 s-BOX12
98 S-DIX
99 S-DIX
100 DAFDS
101 DAF
102 DSA
In the case which ID's were from 1 to 99 it would solve the problem with display full names (in PROJECT_NAME column):
private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox4.SelectedIndex != -1)
{
string[] parts = comboBox4.Items[comboBox4.SelectedIndex].ToString().Split(' ');
textBox10.Text = parts[0];
textBox4.Text = comboBox4.Text.Remove(0, 2).Trim();
}
}
to text box will display full name without ID's for example:
SBOX12, DSA, S-BOX, SBO$, etc
But where the ID's are at least 100 I'm afraid that it won't display full names:
0 sbox, 1 das, 2 S-BOX,
I don't have an idea what i should do.
What I have tried:
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;
using MySql.Data.MySqlClient;
using System.Text.RegularExpressions;
namespace ControlDatabase
{
public partial class InsertStatus : Form
{
MySqlConnection connection;
MySqlCommand command;
MySqlDataReader dr;
Form1 frm1 = (Form1)Application.OpenForms["Form1"];
public InsertStatus()
{
InitializeComponent();
}
private void InsertStatus_Load(object sender, EventArgs e)
{
connection = new MySqlConnection();
connection.ConnectionString = "datasource=localhost;port=3306;username=root;password=";
connection.Open();
string selectQuery5 = "SELECT ID, PROJECT_NAME FROM projekt1.projects";
MySqlCommand command5 = new MySqlCommand(selectQuery5, connection);
MySqlDataReader reader5 = command5.ExecuteReader();
while (reader5.Read())
{
comboBox4.Items.Add(reader5.GetString("ID") + " " + reader5.GetString("PROJECT_NAME"));
}
connection.Close();
}
private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox4.SelectedIndex != -1)
{
string[] parts = comboBox4.Items[comboBox4.SelectedIndex].ToString().Split(' ');
textBox10.Text = parts[0];
textBox4.Text = comboBox4.Text.Remove(0, 2).Trim();
}
}