Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView population of non-bound columns
 

DataGridView population of non-bound columns

I have a form that has a datagridview. Some columns are bound to the datasource, and some are not. The ones that are not I populate from an event. When a new row is added, I use the CellValidating event to populate these. But if I am displaying the records from the datasource (using a filter), my CellValidating is not firing therefore not populating the columns. What is the best event/method to use to get these values populated when the data is displayed from the datasource.

Thanks

  • Moved byHarry ZhuMSFTFriday, August 07, 2009 4:32 AM (From:Visual C# General)
  •  
sandsdad  Wednesday, August 05, 2009 9:38 PM

Hi,

Do you mean you want to add the columns when user adding a new row? There are some events fired when adding a new row. For example, DataGridView.RowsAdded event.

void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)

{

if (!dataGridView1.Columns.Contains("test"))

{

DataGridViewTextBoxColumn txt = new DataGridViewTextBoxColumn();

txt.Name = "test";

txt.HeaderText = "test";

dataGridView1.Columns.Add(txt);

}

}

If I misunderstood you, or you have further questions, please feel free to tell me.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, August 11, 2009 2:09 PM
Any ideas?
sandsdad  Thursday, August 06, 2009 3:34 PM

Hi,

Do you mean you want to add the columns when user adding a new row? There are some events fired when adding a new row. For example, DataGridView.RowsAdded event.

void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)

{

if (!dataGridView1.Columns.Contains("test"))

{

DataGridViewTextBoxColumn txt = new DataGridViewTextBoxColumn();

txt.Name = "test";

txt.HeaderText = "test";

dataGridView1.Columns.Add(txt);

}

}

If I misunderstood you, or you have further questions, please feel free to tell me.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, August 11, 2009 2:09 PM

You can use google to search for other answers

Custom Search

More Threads

• Datagridview CurrentCellChanged Event Fired
• databound DataGridView and hidden column
• NullReferenceException on DataGridView
• combobox and tag property
• How to modify DataGridView values upon Database update
• Making DataGridView DataError set column error text
• Problem with update in tableadapter
• datagridview cellformatting when cell is selected
• Datagrid Problem using MDI forms.
• defining readonly column