Hi, I am using button column in datagridview , i want to change runtime change the text of button. e.g. suppose i have 5 rows and 2 columns (1st column is Test No. and 2nd Column is Start Test) in datagridview. Now am adding the button column to 2nd column name 'Start' . Now in Form load i want to change Button text 'Start' To 'Continue' in case of test pending.

How i can do this..
Thanks in advance.

Hi,
Currently i am using to change text like that way..

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (e.ColumnIndex == 0)
    {
        e.Value = "Change";
    }
}

its working for me but is their is another way...

This logic affects the speed of the datagrid preformance here is my code anybody help me

try
            {

                string compl = "select distinct test_no from testmark where submission='submit'";
                cmd = new SqlCommand(compl, Connect.GetConnection());
                cmd.Connection.Open();
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    CompTest.Add(dr["test_no"].ToString());
                }
                cmd.Connection.Close();

                for (int k = 0; k <= dtgdisplaytest.RowCount - 1; k++)
                {
                    //here checking pending test
                    string TestDisp = dtgdisplaytest[0, k].Value.ToString();
                    string str_sel = "select test_no from testmark where test_no='" + TestDisp + "' and submission='Pause'";
                    cmd = new SqlCommand(str_sel, Connect.GetConnection());
                    cmd.Connection.Open();
                    dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        string TestFindNo = dr["test_no"].ToString();
                        if (TestDisp == TestFindNo)
                        {
                            if (e.ColumnIndex == 4 && e.RowIndex == k)
                            {
                                e.Value = "Continue";
                            }
                        }
                    }
                    cmd.Connection.Close();
                    //here checking completed test
                    foreach (string tno in CompTest)
                    {
                        if (tno == TestDisp)
                        {
                            if (e.ColumnIndex == 4 && e.RowIndex == k)
                            {
                                e.Value = "Submitted";
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {

                FrmMessageBox msg = new FrmMessageBox(ex.Message, "Error");
                msg.ShowDialog();

            }

its slowing the speed.

help me its urgent

for (int k = 0; k <= dtgdisplaytest.RowCount - 1; k++)
{
//here checking pending test
string TestDisp = dtgdisplaytest[0, k].Value.ToString();
string str_sel = "select test_no from testmark where test_no='" + TestDisp + "' and submission='Pause'";

This section of your code will run k SQL queries on the database, is this really want you want to do? You can use a while (dr.Read()) instead of if to iterate through a set of results from a single query. SQL queries are slow in comparison to memory reads, so try to limit them as much as possible.

Also, where are you calling this code?

i am calling this on datagridview__CellFormatting event.

So every time the cell is formatted you are making k calls to the database. I think you need to think about what the cell format should do - it shouldn't retrieve the data but format it in a user-friendly way. By the time the cell format event is fired the data should already have been retrieved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.