I need your help, Please Help me.
Surprising I encounterd another problem which never happened in VB.NET but in C# technique it causing problem.
Here is the explanation :
For testing purposes, Extract data from SQL SERVER NorthWind table Products to display ProductName and UnitPrice on DataGridView and also trying to have specific DataGridView ccolumn format to suit user requirements but it's not working.
Here are the coding:
I have tried both but it doesn't display anything::
Expand|Select|Wrap|Line Numbers
- private void FLoadDataGridViewProductDetails()
- {
- string strSql = "Select ProductName , "
- + " convert(numeric(10,2), UnitPrice ) as UnitPrice "
- + " From Products "
- + " Order by ProductName ";
- sqlconn = new SqlConnection(connstr);
- sqlconn.Open();
- sqlDA = new SqlDataAdapter(strSql, sqlconn);
- sqlDS = new DataSet();
- sqlDS.Clear();
- sqlDA.Fill(sqlDS, "Prod");
- this.DGVProduct.DataSource = sqlDS.Tables["Prod"];
- //Format datagrid column
- FFormatDGVProductColumn(); <----- not working
- this.DGVProduct.ClearSelection();
- this.DGVProduct.MultiSelect = false;
- this.DGVProduct.ReadOnly = true;
- sqlconn.Close();
- } ]
------------------------------------------
// Format specific DataGridView1 columns
Expand|Select|Wrap|Line Numbers
- private void FFormatProductDGVColumn()
- // format datagridview column
- {
- DataGridTableStyle DGVStyle = new DataGridTableStyle();
- DGVStyle.MappingName = "Prod";
- // initialise column to refresh
- this.DGVOrderDetails.Columns.Clear();
- this.DGVOrderDetails.AutoGenerateColumns = false;
- this.DGVOrderDetails.AutoSize = false;
- // create and format column
- //ProductName column
- DataGridTextBoxColumn colProductName = new DataGridTextBoxColumn();
- colProductName.MappingName = "ProductName";
- colProductName.HeaderText = "Product Name";
- colProductName.Width = 250;
- DGVStyle.GridColumnStyles.Add(colProductName);
- // UnitPrice Column
- DataGridTextBoxColumn colUnitPrice = new DataGridTextBoxColumn();
- colUnitPrice.MappingName = "UnitPrice";
- colUnitPrice.HeaderText = "Unit Price";
- colUnitPrice.Width = 90;
- DGVStyle.GridColumnStyles.Add(colUnitPrice);
- }