|
-
Sep 6th, 2009, 05:45 AM
#1
Thread Starter
Frenzied Member
Limiting the DataGridView Rows!!!
I had a DataGridView in which i want to fetch the data from the access database,so i did this code:
Code:
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Etech.mdb"
Dim myConnection As OleDbConnection = New OleDbConnection
myConnection.ConnectionString = connString
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select LAcNo,IssuerName,Creditor,Amount,ROI,EMIAmount,BankAcNo,CreditCardNo,Notes from MLoan", myConnection)
Dim ds As DataSet = New DataSet
DataGridView1.Columns(0).DataPropertyName = "LAcNo"
DataGridView1.Columns(1).DataPropertyName = "IssuerName"
DataGridView1.Columns(2).DataPropertyName = "Creditor"
DataGridView1.Columns(3).DataPropertyName = "Amount"
DataGridView1.Columns(4).DataPropertyName = "ROI"
DataGridView1.Columns(5).DataPropertyName = "EMIAmount"
DataGridView1.Columns(6).DataPropertyName = "BankAcNo"
DataGridView1.Columns(7).DataPropertyName = "CreditCardNo"
DataGridView1.Columns(8).DataPropertyName = "Notes"
da.Fill(ds, "MLoan")
Dim dt As New DataTable
da.Fill(dt)
DataGridView1.DataSource = dt
Now after fetching the data from the database to the DataGridView,i want to remove those columns of the DataGridView where the columns does not contain any value;
i.e,the columns with no contents......
Initially my design form looks like this:
Attachment 73025
After the load button click it looks like this:
Attachment 73026
In the above snapshot,after fetching the data from the access database to the DataGridView,i want to remove the PplicyHolderName,PremiumAmount and a few other columns since these are the columns which do not contain any data....
How to do this?
Thank you
Last edited by gautamshaw; Feb 21st, 2010 at 01:21 PM.
-
Sep 6th, 2009, 05:56 AM
#2
Member
Re: Limiting the DataGridView Rows!!!
Hi,
Did you try:
Code:
DataGridView1.Columns(8).Visible=False
-
Sep 6th, 2009, 06:05 AM
#3
Re: Limiting the DataGridView Rows!!!
Would it not be better to just exclude those columns from the query in the first place, or do you need them for other purposes?
-
Sep 6th, 2009, 06:09 AM
#4
Thread Starter
Frenzied Member
Re: Limiting the DataGridView Rows!!!
ya jmc,i cant exclude those columns in the first place since i need them for some other purpose..
i think this code:
Code:
DataGridView1.Columns(8).Visible=False
is not bad.......
I thought a lots of this and that except the easiest way to do the needful.......
-
Sep 6th, 2009, 11:21 AM
#5
Re: Limiting the DataGridView Rows!!!
Let's think about this. What would be the better option:
1. Create all the grid columns and then hide some of them, thereby creating a whole bunch of objects that will never be used.
2. Create only the columns that are required in the first place.
-
Sep 6th, 2009, 11:26 AM
#6
Thread Starter
Frenzied Member
Re: Limiting the DataGridView Rows!!!
ya jmc....you are right
the 2nd one is a better option
-
Sep 6th, 2009, 11:35 AM
#7
Re: Limiting the DataGridView Rows!!!
You would set the AutoGenerateColumns property of the grid to False, which can only be done in code and obviously must be done before the DataSource is set, which is when the columns would be automatically generated. You would then add only the columns you need at design time. You set the DataPropertyName of each grid column so it knows which table column to bind to.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|