store multiple value on enter with 1 textbox?

1k views Asked by At

In C# with LiteDB i working on a little project, I'm searching for a way to add entry to a datagridview with 5 columns + 1 Textbox.

On datagridView, i have a colID so if i enter on textbox dev5 dgv select this row and i can write on their row like this example:

on textbox i type :

dev5 [Enter] -> line selected by dgv -> 2 [Enter] -> 5 [Enter]..

 |colID |col2|col3|col4|col5|
 |--------------------------|
 |dev3  |    |    |    |    |
 |dev4  |    |    |    |    |
 |--------------------------|
*|dev5  | 2  |  5 |    |    |
 |--------------------------|
 |dev6  |    |    |    |    |
------------------------------

I need to store value of textbox on [Enter] to a array like {dev5,2,5,"",""}

and Insert to database in one shot because Actually, on every [enter] its update my table like this :

dev5;2
dev5;2;5
dev5;2;5;8
dev5;2;5;8;9

Like you see, it's not optimized so for a better result but i need just the last line..

Any idea for solving this problem are welcome

1

There are 1 answers

1
JD Davis On BEST ANSWER

One potential method would look something like this

public List<string> Values = new List<string>();
public void UpdateValues()
{
    var value = textBox1.Text;

    Values.Add(value);
    textBox1.Clear();

}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char) Keys.Return)
    {
        UpdateValues();
    }
}