VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,464 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,649 people online right now. Registration is fast and FREE... Join Now!




DataGridView change column type programatically

 

DataGridView change column type programatically

foxbymariuss

1 Jul, 2009 - 11:48 PM
Post #1

New D.I.C Head
*

Joined: 14 May, 2009
Posts: 10

Hello,

I have the following problem regarding DataGridView. I am kinda newbie to VB, so I apologize if the question is a stupid one.

So:
I am using VB 2008.
I have a DataGridView that I use for the output of a SQL select statement. The application composes the SQL select statement, runs it against the database, puts the result in a dataadapter that fills a datatable. The datatable is then set as Datasource for the Datagridview. The DGV column headers are the aliases from the SQL select statement.
The select Statement returns a column that is of datatype Date. The user needs to edit that column. It's much easier to do this via a calendar control (or date - time picker). So using the example found at http://msdn.microsoft.com/en-us/7tas5c80.aspx
I managed to create a column of type date that can be edited by selecting a date from a calendar control.
What I need and don't know how to do is how to set a certain column (that is of date datatype) to be of a certain type (date picker combo box) after binding the datatable to the DGV(after setting the datasource for DGV as being the datatable).
Can anyone please help me with this?

Thank you for any suggestions.

User is offlineProfile CardPM
+Quote Post


firebolt

RE: DataGridView Change Column Type Programatically

2 Jul, 2009 - 03:18 AM
Post #2

D.I.C Lover
Group Icon

Joined: 20 Feb, 2009
Posts: 5,463



Thanked: 75 times
Dream Kudos: 1675
My Contributions
Can we see the code that you are working on please? smile.gif
User is offlineProfile CardPM
+Quote Post

SpeeDemon

RE: DataGridView Change Column Type Programatically

2 Jul, 2009 - 10:58 AM
Post #3

New D.I.C Head
*

Joined: 18 Mar, 2008
Posts: 44


My Contributions
I too am interested in seeing some code as I am working on a similar situation (Also a noobie) smile.gif
User is offlineProfile CardPM
+Quote Post

foxbymariuss

RE: DataGridView Change Column Type Programatically

6 Jul, 2009 - 04:52 AM
Post #4

New D.I.C Head
*

Joined: 14 May, 2009
Posts: 10

Yes, of curse. Here it is:



CODE

Dim orclstr As String = "Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(CID=GTU_APP)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.0.0.9)(PORT=1523)))(CONNECT_DATA=(SID=orcl)(SERVER=DEDICATED)));User Id=user;Password=pass;"
            Dim strsql As String = "select transportercode as ""Airline"", flightnr as ""Flight Nr."", nvl2(nullif(is_nil,0),'Yes','No') as ""Is NIL"", flight_date as ""Date"", depart_airport as ""Departure"", unloading_airp as ""Destination"", nvl(truck,'N/A') as ""truck"", nvl(aircraft_code, 'N/A') as ""Aircraft Code"", obs as ""Observations"" from ffm where flightnr='" + ListBox1.SelectedValue + "' and flight_date=to_date('" + CStr(DateTimePicker1.Value.Day) + "-" + CStr(DateTimePicker1.Value.Month) + "-" + CStr(DateTimePicker1.Value.Year) + "','dd-mm-yyyy')"
dim dt as datatable = new datatable

'flight_date is a calendar date data type

Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(strsql, orclstr)

da = New OleDb.OleDbDataAdapter(strsql, orclstr)

Me.DataGridView2.DataSource = dt




I want the user to be able to edit the field "flight_date". As the app runs now, the data is presented in the cells of this columns like: 30/04/2009 .
The user can edit it, but unless he enters a valid date, in the format dd/mm/yyyy , an error is raised.
For limiting user bad input, I want the user to be able to pick a calendar date from a picker.


To create a column with datetimepicker, I used the code found at: http://msdn.microsoft.com/en-us/7tas5c80.aspx[/url]


With this I can create a column with date picker, but only before the binding:
CODE

Me.DataGridView2.DataSource = dt


I want the column type of flight_date column to be date picker.
How can I do that? How to change the column type after binding? Or, how to declare the DGV column type and bind it after this?

If you have any other suggestions, I would be grateful.

Thanks a lot.


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 02:23AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month