Click here to Skip to main content
15,944,837 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how can I set value from textbox suppose if I add value in textbox 17 then it should be considered as 0-17 in datagridview, and then if I add 35 it should be 17-35 in datagridview and suppose after adding two value I am adding third value 25 then it should be 0-17,17-25 and 25-35.


What I have tried:

the no. should be between 0 to 100 only and thats I have already done in textbox event. currently I am adding a value directly from text box to datagrid view.
Screenshot-49 — ImgBB[^]



private void AddButton_Click(object sender, EventArgs e)
        {
            
            
            try
            {
                connection = new OleDbConnection("provider=microsoft.ace.oledb.12.0;data source=F:\\Floro_sense\\Floros.mdb");
                connection.Open();
               // if (FloroValueExists(ValueTextBox.Text)) { MessageBox.Show("The floro Value already exists."); return; }
                if (FloroTypeExists(TypeTextBox.Text)) { MessageBox.Show("The floro type already exists."); return; }
               

                OleDbCommand command = new OleDbCommand("INSERT INTO Sflorotype(Sflorovalues, Sflorotypes) VALUES ('" + ValueTextBox.Text + "','" + TypeTextBox.Text + "');", connection);
                var result = command.ExecuteNonQuery();

                OleDbDataAdapter adapter = new OleDbDataAdapter("select * from Sflorotype", connection);
                DataTable table = new DataTable();
                adapter.Fill(table);

                var data = string.Join(Environment.NewLine,
                table.Rows.OfType<DataRow>().Select(x => string.Join(" ; ", x.ItemArray)));

                BindingSource bind = new BindingSource();
                bind.DataSource = table;
                dataGridViewList.DataSource = bind;
                adapter.Update(table);

               
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                connection.Close();

            }

        }


private void ValueTextBox_TextChanged(object sender, EventArgs e)
        {
            //Add a reference to Microsoft.VisualBasic.dll

            if (Microsoft.VisualBasic.Information.IsNumeric(this.ValueTextBox.Text))

            {

                int i;

                int.TryParse(this.ValueTextBox.Text, out i);

                if (!(i > -1) || !(i < 101))

                {

                    this.ValueTextBox.Clear();

                }

            }

            else

            {

                this.ValueTextBox.Clear();

            }

        }
Posted
Updated 22-Dec-22 1:12am
v2
Comments
Richard Deeming 22-Dec-22 6:57am    
That description presumably makes sense to you, but the rest of us are left with no idea what you are trying to do, what you have tried, or where you are stuck.

Click the green "Improve question" link and update your question to include a clear and complete description of what you want your code to do, the relevant parts of your code, the full details of any errors, and the details of what you have tried and where you are stuck.

1 solution

I'd create a class to hold the ranges, with a static List<MyRangeClass> to hold all instances. In the class constructor, add the new instance to the list, and sort it by the value you entered. You can then get the upper and lower bounds from the current value and the previous one.

Then just use the list as the DataSource for the DGV instead of adding items manually.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900