none
I want to stop listing RRS feed

  • Question


  • private void AddData2Rows(String pEventMessage)
            {
                try
                {              
                    DataGridViewRow tRow = (DataGridViewRow)dgvSearchView.Rows[0].Clone();
                    DataParser.MessageFrame gMessageParser = new DataParser.MessageFrame();
                    if(gMessageParser.CheckRTMMessage(pEventMessage))
                    {
                        if(gMessageParser.gData.Contains("SEARCH"))
                        {
                            if(gMessageParser.gData.Contains("STOPPED"))
                            {
                                //<KO><TODO> if need do something
                            }
                        }
                        else if(gMessageParser.gData.Contains("ADDED"))
                        {
                            String tMessage = gMessageParser.gData;
                            String[] tDataVals = tMessage.Split(';');
                            tRow.Cells[0].Value = tDataVals[1];
                            tRow.Cells[1].Value = tDataVals[2];
                            tRow.Cells[2].Value = "Not Defined Yet";
                            tRow.Cells[3].Value = "Not Defined Yet";
                            dgvSearchView.Rows.Add(tRow);
                        }                                       
                    }
                }
                catch (Exception ex)
                {
                    //<KO><TODO> add ex message
                }

    I listing data in DataGridView. I want to stop the process with the button. This my code for adding datagridview. I want to click the button and this listing code will stop.



    Tuesday, February 5, 2019 9:08 AM

Answers

  • The following does not match your current logic but might spark ideas.

    https://code.msdn.microsoft.com/Populate-DataGridView-via-a3ede35a?redir=0


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, February 5, 2019 5:09 PM
    Moderator
  • Hi Burakhan Bircan,

    As Andrey Belyakov mentioned, we could achieve it via Events' Subscribe and Unsubscribe , Here is a simple sample for your reference.

    delegate void MyDele(string str);
        public partial class Form12 : Form
        {
            public Form12()
            {
                InitializeComponent();
            }
    
            event MyDele MyEvent;  
            private void AddData2Rows(String pEventMessage)
            {
                MessageBox.Show("Done" + pEventMessage);
                try
                {
                    DataGridViewRow tRow = (DataGridViewRow)dgvSearchView.Rows[0].Clone();
                    //DataParser.MessageFrame gMessageParser = new DataParser.MessageFrame();
                    //if (gMessageParser.CheckRTMMessage(pEventMessage))
                    //{
                    //    if (gMessageParser.gData.Contains("SEARCH"))
                    //    {
                    //        if (gMessageParser.gData.Contains("STOPPED"))
                    //        {
                    //            //<KO><TODO> if need do something
                    //        }
                    //    }
                    //    else if (gMessageParser.gData.Contains("ADDED"))
                    //    {
                    //        String tMessage = gMessageParser.gData;
                    //        String[] tDataVals = tMessage.Split(';');
                    //        tRow.Cells[0].Value = tDataVals[1];
                    //        tRow.Cells[1].Value = tDataVals[2];
                    //        tRow.Cells[2].Value = "Not Defined Yet";
                    //        tRow.Cells[3].Value = "Not Defined Yet";
                    //        dgvSearchView.Rows.Add(tRow);
                    //    }
                    //}
                }
                catch (Exception ex)
                {
                    //<KO><TODO> add ex message
                }
            }
            private void button1_Click(object sender, EventArgs e)
            {
                this.MyEvent -= new MyDele(AddData2Rows);
            }
    
            private void Form12_Load(object sender, EventArgs e)
            {
                this.MyEvent += new MyDele(AddData2Rows);
                AddData2Rows("TEst");
            }
        }

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 6, 2019 2:38 AM
    Moderator

All replies

  • Hello,

    Sorry, do not understand what exactly you want to stop:

    - stop listening?

    - stop application?

    - where you want a button?

    Depends on what you need there will be lot of options:

    - create and assign event handler for overloaded grid

    - use Application.Exti()/Terminate()(?) for stopping application

    - create button in the cell with some kind of ID for what is beside...


    Sincerely, Highly skilled coding monkey.

    Tuesday, February 5, 2019 9:20 AM
  • I will create any button and I want to stop adding in datagridview.
    Tuesday, February 5, 2019 9:57 AM
  •  I want to stop adding in datagridview

    ------

    Declare a delegate and assign AddData2Rows() to delegate handler. 
    When you need to stop processing - detach handler. 


    Sincerely, Highly skilled coding monkey.

    Tuesday, February 5, 2019 10:43 AM
  • I would add a timer, and list items on the data grid view second by second.
    Add a "add" button, and put timer.start() inside
    And then add the timer.stop() inside a "stop" button, so I can stop it.

    Because if u have a button to add items do the data grid view, once u click it will fill all, unless you only add a certain amount.


    BP-LP 2005/2016 @ll rights reserved

    Tuesday, February 5, 2019 4:19 PM
  • The following does not match your current logic but might spark ideas.

    https://code.msdn.microsoft.com/Populate-DataGridView-via-a3ede35a?redir=0


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, February 5, 2019 5:09 PM
    Moderator
  • Hi Burakhan Bircan,

    As Andrey Belyakov mentioned, we could achieve it via Events' Subscribe and Unsubscribe , Here is a simple sample for your reference.

    delegate void MyDele(string str);
        public partial class Form12 : Form
        {
            public Form12()
            {
                InitializeComponent();
            }
    
            event MyDele MyEvent;  
            private void AddData2Rows(String pEventMessage)
            {
                MessageBox.Show("Done" + pEventMessage);
                try
                {
                    DataGridViewRow tRow = (DataGridViewRow)dgvSearchView.Rows[0].Clone();
                    //DataParser.MessageFrame gMessageParser = new DataParser.MessageFrame();
                    //if (gMessageParser.CheckRTMMessage(pEventMessage))
                    //{
                    //    if (gMessageParser.gData.Contains("SEARCH"))
                    //    {
                    //        if (gMessageParser.gData.Contains("STOPPED"))
                    //        {
                    //            //<KO><TODO> if need do something
                    //        }
                    //    }
                    //    else if (gMessageParser.gData.Contains("ADDED"))
                    //    {
                    //        String tMessage = gMessageParser.gData;
                    //        String[] tDataVals = tMessage.Split(';');
                    //        tRow.Cells[0].Value = tDataVals[1];
                    //        tRow.Cells[1].Value = tDataVals[2];
                    //        tRow.Cells[2].Value = "Not Defined Yet";
                    //        tRow.Cells[3].Value = "Not Defined Yet";
                    //        dgvSearchView.Rows.Add(tRow);
                    //    }
                    //}
                }
                catch (Exception ex)
                {
                    //<KO><TODO> add ex message
                }
            }
            private void button1_Click(object sender, EventArgs e)
            {
                this.MyEvent -= new MyDele(AddData2Rows);
            }
    
            private void Form12_Load(object sender, EventArgs e)
            {
                this.MyEvent += new MyDele(AddData2Rows);
                AddData2Rows("TEst");
            }
        }

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 6, 2019 2:38 AM
    Moderator