Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

datagridview not using column names from database table

$
0
0

I program in vb.net and have a datagridview that is automatically populated from a database.   When I use code such as dgvPurchases.Rows(dgvPurchases.SelectedRows(i).Index).Cells("Head").Value to work with a value from the dgv, I receive an error column name "Head" not found.   This is the column name in my datatable and when I do an edit Columns, it shows "Head" as the DataPropertyName.   One answer on the web was to rename the column, but I can find out how to rename the Header, but not the column.   When I go to Purchases.Designer.vb, I find       Me.HeadDataGridViewTextBoxColumn = New System.Windows.Forms.DataGridViewTextBoxColumn().   On columns added to the database after I originally designed the form, they show      Me.CkOff = New System.Windows.Forms.DataGridViewTextBoxColumn() and dgvPurchases.Rows(dgvPurchases.SelectedRows(i).Index).Cells("CkOff").Value returns a value.

I know I can use the column number; however, if I change the datatable, correcting the code becomes problematic.   Using data column names is much preferable


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>