Hello again...
I have a DGV populated thru a BindingSource that shows me some values from the database. In the same DGV i have an empty Column...
How can i populate the second column for example; Column 2 = Column 1 + 10 ?
Thanks in advice!
Printable View
Hello again...
I have a DGV populated thru a BindingSource that shows me some values from the database. In the same DGV i have an empty Column...
How can i populate the second column for example; Column 2 = Column 1 + 10 ?
Thanks in advice!
I assume that the BindingSource is bound to a DataTable. Is that empty column in the DataTable or is it an unbound column in the grid only? This would be much easier if it was in the DataTable.
The second column i want to be unbounded because is just for information propouse only. It will not be used to be stored into a database or somethink like this...
Even if it has nothing to do with the database you can still add the column to the DataTable. It's just that doing so makes everything much easier because the DataColumn can handle everything for you. Otherwise you'd have to handle events and perform the calculation yourself. It could look something like this:That's all you have to do. The grid will create the display column automatically and the table will handle generating the values for the evaluated column. There's no issue when saving either because, unless you explicitly tell it to, there will be no attempt to save that column to the database.vb.net Code:
Dim table As New DataTable adapter.Fill(table) table.Columns.Add("Column2", GetType(Integer), "Column1 + 10") grid.DataSource = table
???Code:Unable to cast object of type 'System.Data.DataTable' to type 'oft_produseDataTable'.
So you're using a typed DataSet, with typed DataTables and TableAdapters instead of DataAdapters. You have to create an instance of your typed oft_produseDataTable class instead of the standard DataTable class. I've never tried but I don't see why you wouldn't be able to add a new column to it still. It is derived from DataTable so it's still got all the members a DataTable has.