473,383 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

DataGridView Column Format not display data in DataGridView

126 100+
Hi Fellow Good Guys,

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
  1.  private void FLoadDataGridViewProductDetails()
  2.    {
  3.       string strSql = "Select  ProductName ,  "
  4.                           + " convert(numeric(10,2), UnitPrice ) as UnitPrice "
  5.                           + " From Products  " 
  6.                           + " Order by ProductName ";
  7.  
  8.         sqlconn = new SqlConnection(connstr);
  9.         sqlconn.Open();
  10.         sqlDA = new SqlDataAdapter(strSql, sqlconn);
  11.         sqlDS = new DataSet();
  12.         sqlDS.Clear();
  13.  
  14.         sqlDA.Fill(sqlDS, "Prod");
  15.         this.DGVProduct.DataSource = sqlDS.Tables["Prod"];
  16.  
  17.    //Format datagrid column
  18.          FFormatDGVProductColumn();   <----- not working 
  19.  
  20.           this.DGVProduct.ClearSelection();
  21.           this.DGVProduct.MultiSelect = false;
  22.           this.DGVProduct.ReadOnly = true;
  23.           sqlconn.Close();            
  24.  }  ]

------------------------------------------


// Format specific DataGridView1 columns
Expand|Select|Wrap|Line Numbers
  1.   private void FFormatProductDGVColumn()  
  2.    // format datagridview column
  3.     {
  4.        DataGridTableStyle DGVStyle = new DataGridTableStyle();
  5.        DGVStyle.MappingName = "Prod";
  6.  
  7.   // initialise column to refresh 
  8.       this.DGVOrderDetails.Columns.Clear();
  9.       this.DGVOrderDetails.AutoGenerateColumns = false;
  10.       this.DGVOrderDetails.AutoSize = false;
  11.  
  12.   // create and format column 
  13.  
  14. //ProductName column 
  15.       DataGridTextBoxColumn colProductName = new DataGridTextBoxColumn();
  16.       colProductName.MappingName = "ProductName";
  17.       colProductName.HeaderText = "Product Name";
  18.       colProductName.Width = 250;
  19.      DGVStyle.GridColumnStyles.Add(colProductName);
  20.  
  21.  // UnitPrice Column
  22.      DataGridTextBoxColumn colUnitPrice = new DataGridTextBoxColumn();
  23.      colUnitPrice.MappingName = "UnitPrice";
  24.      colUnitPrice.HeaderText = "Unit Price";
  25.      colUnitPrice.Width = 90;
  26.      DGVStyle.GridColumnStyles.Add(colUnitPrice);                          
  27.  }
Apr 6 '10 #1
0 2380

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: thomasp | last post by:
I have a datagridview in vb.net 2005 that pulls its data from an Access Database. The database has a time column. When you view the data in Access it shows only a time in 24hour format. When the...
1
by: mark carew | last post by:
Hi, Problem - An extra column to the left (even with row headers disabled) ---------------------------------------------------------- Apologies if this posting is already in the newsgroup; but...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
3
by: sklett | last post by:
I'm changing from a DataGrid to a DataGridView and have run across a problem. The items that are bound to the DataGrid have an int Property that represents a primary key of a lookup table in my...
130
by: Daniel Manes | last post by:
I'm baffled. I have a column in a SQL Server Express database called "Longitude," which is a float. When I view the table in a DataGridView, some of the numbers, which only have two decimal places...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
5
by: TheSteph | last post by:
Hi ! I have a DataGridView with a Date (DateTime) Column. When a user edit the cell and change the date I woulk like to allow him to write "081501" and programmatically transform the entered...
3
by: Cdude | last post by:
I am using this code at the moment to format the column this.itemsDataGrid.Columns.DefaultCellStyle.Format = "c"; but i get the error "Object reference not set to an instance of an object. "...
1
by: TG | last post by:
Hi! I have an application in which I have some checkboxes and depending which ones are checked those columns will show in the datagridview from sql server or no. After that I have 2 buttons:...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.