Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > datagridview design!
 

datagridview design!

Hello I have a problem to solv. I have a search function that builds a report in a datagridview. I have a datatable to display the matched data. But now I want to display the found data in realtime and update the row in the datagridwhen found. The user will now see when data is found (when it is found). My search function can take time, up til 10 minutes so I will use the datagridview in my windows form to show a little progress. ( I have a progressbar also...).

I hope someone can help me with a link or some code example to show...

Jonte2  Tuesday, June 12, 2007 8:56 AM

Hi,

You could try this, I have ran an example here and it works in my case but whether it works in your project I don't know.

What I did was create a method that populated the list and also a delegate that could be used to represent that method. The method just adds 100 records to a data table stored in a dataset. The datagridview is bound to this table.

Code Snippet

delegate void Fill();

public void OnFill()

{

for (int i = 0; i < 100; i++)

{

data.ExampleTable.AddExampleTableRow(i.ToString(), "value");

Application.DoEvents();

System.Threading.Thread.Sleep(100);

}

}

Then I created an instance of the delegate andused it inthe DataGridViews BeginInvoke method.

Code Snippet

Fill FillGrid = new Fill(OnFill);

this.dataGridView1.BeginInvoke(FillGrid);

The Datagridview slowly populates as the table fills up.

Derek Smyth  Tuesday, June 12, 2007 9:49 AM

Hi,

You could try this, I have ran an example here and it works in my case but whether it works in your project I don't know.

What I did was create a method that populated the list and also a delegate that could be used to represent that method. The method just adds 100 records to a data table stored in a dataset. The datagridview is bound to this table.

Code Snippet

delegate void Fill();

public void OnFill()

{

for (int i = 0; i < 100; i++)

{

data.ExampleTable.AddExampleTableRow(i.ToString(), "value");

Application.DoEvents();

System.Threading.Thread.Sleep(100);

}

}

Then I created an instance of the delegate andused it inthe DataGridViews BeginInvoke method.

Code Snippet

Fill FillGrid = new Fill(OnFill);

this.dataGridView1.BeginInvoke(FillGrid);

The Datagridview slowly populates as the table fills up.

Derek Smyth  Tuesday, June 12, 2007 9:49 AM

Perfect, thank you very much...now it works nice and smooth, I made it like this, it was very simple:

DataTable dt = new DataTable();

DataRow dr;

private void AddStringToGrid(String s, String s2)

{

dr = dt.NewRow();

string str = s2;

dr[0] = count;

count++;

dr[2] = s;

str = s.Remove(0, s.IndexOf(find) + 2);

dr[1] = str;

dt.Rows.Add(dr);

Thread.Sleep(100);

dataGridView1.DataSource = dt; //Now datagrid is updated by the datatable and then its easy to export datatable to excel...

dataGridView1.Update();

}

Jonte2  Wednesday, June 13, 2007 1:18 PM

You can use google to search for other answers

Custom Search

More Threads

• ListView gridline rendering issue
• Forms Based Login - Plz can anybody tell whats wrong in this code?
• DataGridView checkbox column
• Bug in binding textbox to Child Table??
• Printing Datagridview with Salan Al-Ani's Class - How to add to it?
• DatagridviewComboboxColumn Draw Text Only
• Combo Box - Data binding
• DataGridView and Threads Problem
• DefaultView problem
• User login validation