I need to populate a table with a list of paramaters comming from a business
object as properties. I do not want the normal dataview were a property is
represented by a column. Instead I would like for example two columns. The
first shall contain the names of the parameters and the second column the
values of the parameters. The values are run-time values so they are updated
several times per second. So I will have a list like this:
COLUMN1 COLUMN2
par1.Name par1.Value
par2.Name par2.Value
par3.Name par3.Value
Is there a way for me to databind a cell each time I add a row in the table?
Something like:
datagridview.Databindings.Add("Rows[0].Cells[1].Value", par1, "Value");
(I no this syntax do not work)
Linda Liu [MSFT] - 25 Jan 2007 10:29 GMT
Hi Patrik,
DataGridView can only support complex data binding, so it is impossible for
us to bind a cell in a DataGridView to a data source separately.
In my opinion, you have two options to get what you want.
One option is to fill the data into the cells within the DataGridView by
yourself. The following is a sample.
this.dataGridView1.RowCount = 3;
this.dataGridView1.ColumnCount = 2;
this.dataGridView1.Rows[0].Cells[0].Value = "par1.name";
this.dataGridView1.Rows[0].Cells[1].Value = "par1.value";
this.dataGridView1.Rows[1].Cells[0].Value = "par2.name";
this.dataGridView1.Rows[1].Cells[1].Value = "par2.value";
this.dataGridView1.Rows[2].Cells[0].Value = "par3.name";
this.dataGridView1.Rows[2].Cells[1].Value = "par3.value";
When you'd like to update the data in the DataGridView, you have to update
it by yourself.
The other option is to make use of a DataTable, which has two columns(one
column is fo r the property name and the other column is for property
value) and contains the names and values of all the properties of your
business object. You could then bind the DataGridView to the DataTable.
When you'd like to update the data in the DataGridView, you could just
update the data in the DataTable, and data binding will update the data in
the DataGridView automatically.
Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Linda Liu [MSFT] - 29 Jan 2007 12:27 GMT
Hi Patrik,
How about the problem now?
If the problem is still not solved, and you need our further assistance,
please feel free to let me know.
Thank you for using our MSDN Managed Newsgroup Support Service!
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.