Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: .NET3.0 C#
i m getting problem in showing data in gridview column........actually i have 4 column in my datagridview , when i retrive data from database and store data in dataset and when i connect dataset to datarid view then it create 4 new column but i want to show data in existes column......
so plz help me......
Posted 30-Oct-12 21:08pm
satz_770 at 31-Oct-12 3:14am
Pls. explain ur problem more clearly...
shambhoo kumar at 31-Oct-12 3:19am
i m showing data in gridview from dataset..
and i have already created 4 column but when i retrive datafrom data set then it create 4 new column and showing record ,but i want to show record in existens column
shambhoo kumar at 31-Oct-12 6:59am
any one help me
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I solve my self........
SqlConnection con = new SqlConnection("Data Source=.; Initial Catalog=sham; Integrated Security=True");
SqlDataAdapter da = new SqlDataAdapter("Select Name,Address from Employee", con);
DataSet ds = new DataSet();
CustName.DataPropertyName = "Name";
CustAddress.DataPropertyName = "Address";
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = ds.Tables[0].DefaultView;
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I would programmatically add the records in the dataset to the datagridview.
For example like this:
- Create class that matches a record (with properties matching the fields)
Class OneRecord
public int UID { get; set; }
public string Name { get; set; }
public DateTime Date { get; set; }
public bool Checked { get; set; }
- Create BindingList of this class
Private BindingList<OneRecord> MyList = new ...
- Reference DataSource of datagridview to instance of BindingList
this.dgv.DataSource = this.MyList;
- Add records to instance of BindingList as instances of the class, need some logic for this
- Refresh datagridview
This way you don't need to worry about behavior of dataset vs gridview etc.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 405
1 CPallini 375
2 BillWoodruff 314
3 George Jonsson 279
4 OriginalGriff 227
0 OriginalGriff 5,030
1 CPallini 4,225
2 Sergey Alexandrovich Kryukov 3,604
3 George Jonsson 2,831
4 Gihan Liyanage 2,386

Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100