4 Replies - 24663 Views - Last Post: 15 June 2010 - 10:04 PM Rate Topic: -----

#1 foxbymariuss  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 14-May 09

DataGridView change column type programatically

Posted 02 July 2009 - 12:48 AM

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.microsof...s/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.

Is This A Good Question/Topic? 0
  • +

Replies To: DataGridView change column type programatically

#2 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Re: DataGridView change column type programatically

Posted 02 July 2009 - 04:18 AM

Can we see the code that you are working on please? :)
Was This Post Helpful? 0
  • +
  • -

#3 SpeeDemon  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 18-March 08

Re: DataGridView change column type programatically

Posted 02 July 2009 - 11:58 AM

I too am interested in seeing some code as I am working on a similar situation (Also a noobie) :)
Was This Post Helpful? 0
  • +
  • -

#4 foxbymariuss  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 14-May 09

Re: DataGridView change column type programatically

Posted 06 July 2009 - 05:52 AM

Yes, of curse. Here it is:



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.microsof...s/7tas5c80.aspx[/url]


With this I can create a column with date picker, but only before the binding:
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.
Was This Post Helpful? 0
  • +
  • -

#5 taps k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-June 10

Re: DataGridView change column type programatically

Posted 15 June 2010 - 10:04 PM

View Postfoxbymariuss, on 06 July 2009 - 04:52 AM, said:

Yes, of curse. Here it is:



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.microsof...s/7tas5c80.aspx[/url]


With this I can create a column with date picker, but only before the binding:
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.


Hello foxbymariuss
i am newbi in .net framework
you get any solution for your problem i face same problem if ypu have solution please tell me
thanks in advance

i have datagrid in program containing various columns in that one column contains datatime in double datatype format and i am unble to change that runtime into datatime datatype any one can suggest me for this problem
thanks in advance
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1