Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > DataGrid: how to populate the text in a datagrid?
 

DataGrid: how to populate the text in a datagrid?

Hi,

I am developing an addin for visual studio 2005-using C#.
I have developed a tool window where i need to display the output of a function in the datagrid of the toolwindow.
The output is the List content which needs to be displayed.

First i have developed a class:
class line_num_keywords
{
public int line_number;
public string captured_word;
public line_num_keywords(int l_no,string c_key)

{
this.line_number = l_no;
this.captured_word = c_key;
}

Where this class stores the line number and words in a list:

List<line_num_keywords> data_holder = new List<line_num_keywords>();
.
.
.
.
data_holder.Add(new line_num_keywords(e.Line,input_array[keyword_number]));


This List created- has to bedisplayed in the datagrid.
how can i achieve this? please can any one help me with the code?
The list has to be displayed when the toolWindow is loaded.

Thanks,
Nayana





Nayna  Wednesday, December 17, 2008 9:07 AM
Hi NavanaKalkur,

It is not very complicated to binding the List<> with DataGridView.
Just set the DataSource property is OK.
List<line_num_keywords> data_holder = new List<line_num_keywords>();
data_holder.Add(new line_num_keywords(e.Line,input_array[keyword_number]));
...
dataGridView1.DataSource = data_holder;

Everything is fine, isn't it??

If there's any problem, please feel free to let me know.

Best regards,
Steven Yu
  • Marked As Answer bySteven.Yu Monday, December 22, 2008 4:55 AM
  •  
Steven.Yu  Thursday, December 18, 2008 6:48 AM
Hi NavanaKalkur,

It is not very complicated to binding the List<> with DataGridView.
Just set the DataSource property is OK.
List<line_num_keywords> data_holder = new List<line_num_keywords>();
data_holder.Add(new line_num_keywords(e.Line,input_array[keyword_number]));
...
dataGridView1.DataSource = data_holder;

Everything is fine, isn't it??

If there's any problem, please feel free to let me know.

Best regards,
Steven Yu
  • Marked As Answer bySteven.Yu Monday, December 22, 2008 4:55 AM
  •  
Steven.Yu  Thursday, December 18, 2008 6:48 AM

You can use google to search for other answers

Custom Search

More Threads

• Is my plant alive ?
• Trouble with <Null> values in Date Fields
• Problem with the configurationManager Class
• Default Publish Setting
• Install Sheild
• Fotovision Enhancement
• HELP!! There are no animals!
• The type or namespace name 'DSN' could not be found
• Creating Progressbar control in gridview column
• Server Downtime [Updated 07/07/2004 @ 3:12pm PDT]