Passing value from DataGridView to DateTimePicker - vb.net

When I am passing value from DataGridView to a DateTimePicker, I am getting this error
String was not recognized as a valid DateTime
and here is my code
Dateadd.Value = Convert.ToDateTime(DGVTest(0,DGVTest.SelectedRows(0).Index).Value)

Does this work?:
Dateadd.value = CDate(DGVTest(0, DGVTest.SelectedRows(0).Cells(0).value
It looks as if you code is just returning the value of the index of row (0), so just 0?
Do you need to get the date time value from a cell withing the grid view? The code you have written does not do that. In that case try:
Dateadd.value = CDate(DGVTest.Rows(0).Cells(0).value)
Let me know if this works for you.

Related

how do i get the value of a parameter in a CATDrawing and edit it

I want to be able to get the value of the parameter CATDWG_SH_NO. and add the value of Totalsheets1 to it.
So the final strparam1.Value will give me the total of the 2 mentioned before. The code I have right now only updated the parameter value to the totalsheets1 value.
Another issue I faced was that the code will only update the value when the value existed in the parameters multiple value drop-down list, i.e. if the value 10 was not inside the drop-down list, it will fail to update the parameter.
Any help will be appreciated. Thank you.
Function SheetNoUpdate(odoc As Document)
Dim parameters1 As Parameters
Set parameters1 = odoc.Parameters
Set strparam1 = parameters1.Item("CATDWG_REV")
strparam1.Value = "A"
Set strparam1 = parameters1.Item("CATDWG_SH_NO.")
strparam1.Value = Totalsheets1.Value
End Function
I'm not sure if I interpret you question correct: If you like to add the values try:
strparam1.Value = strparam1.Value + Totalsheets1.Value
'or if both are strings
strparam1.Value = CStr(CInt(strparam1.Value) + CInt(Totalsheets1.Value))
Or do you want to create a formula?
On an multi-value parameter you can get the values (array) with GetEnumerateValues and SetEnumerateValues to assign an array.

Null values are creating error in datagridview in vb.net

So i am importing the Excel sheet into datagridview. But unfortunately some empty tuples are included inside. The image will be of some help. The extra NULL tuples are 41 and 42. Now when i am calculating the percentage from the data of these tuples with a loop, the loop hits these empty rows and shows the
Error:{"Conversion from type 'DBNull' to type 'Integer' is not valid."}
.
What to do..Any suggestions will be of great help!Thank you...
You can insert an If condition to first evaluate if the cell contents are dbnull. Here is an example where I use it in some of my own projects:
If IsDBNull(part.Item("Assignment Category")) = False Then
newOracleHREmployeeRecord.AssignmentCategory = CStr(part.Item("Assignment Category"))
End If

How to get the previous column value using datareader

Hi i am trying to get the previous value of my column so I can do a simple calculation my code is like that.
ElseIf data_reader("PCT_HFO") < 0 Then
actual ROBS
Actual_ROBS = data_reader("Distance Run - NM")
+data_reader("PCT_Distance")-"Previous value of data_reader("PCT_Distance")".
New code
Previous_PCT_Distance = 0
DO while....
Actual_Distance = data_reader("Distance Run - NM") + data_reader("PCT_Distance") - Previous_PCT_Distance
Do stuff....
Previous_PCT_Distance = data_reader("PCT_Distance")
Loop
Any ideas?
Data readers are forward-only iterators. I suggest you use a Datatable, rather that data reader. But if u insist on using a data reader, you can use a new variable, say PreviousPCTDistance, that stores the copy of previous datareader value. Initialize the value of this variable to nothing or 0, for the first iteration. At the end of each loop, update this variable with the datareaders value, like :
PreviousPCTDistance = data_reader("PCT_Distance"),
So when your condition is satisfied, to get to use this previous value :
Actual_ROBS = data_reader("Distance Run - NM")+data_reader("PCT_Distance")- PreviousPCTValue
As your using a data reader you are looping though the rows so you just need a second variable previous value which is initially 0 for first record.
You then set this variable to the data reader value after you set Actual_ROBS

how to set a datagridview column to date format

I have created a DataGridView and I add columns to it like this:
Dim col_1 = New DataGridViewTextBoxColumn
col_1.Name = "Date"
col_1.DefaultCellStyle.Format = "MM/dd/yyyy"
data_grid.Columns.Add(col_1)
then I add data to the column like this:
data_grid.Item(1,1).Value = temp_date
The grid is filled with the correct data and everything works, however...when I click on the column headers, the column that shows the dates does not sort correctly (it sorts alphabetically) and I know this is because I set it up as "DataGridViewTextBoxColumn", but there is no option for a date type column. So how to I set it up as a date column so it sorts based on the date when the header is clicked?
Thanks.
You should also set the ValueType of the column:
DataGridView1.Columns(0).ValueType = GetType(Date)
Then convert date_temp to a Date-value before assigning this to the cell's Value.
Using CDate could be your first attempt:
data_grid.Item(1,1).Value = CDate(temp_date)
otherwise, investigate Parse, TryParse or Convert, to obtain the date-value.

DateTime format in Ultragrid column

I have set a specific format for a column in an Ultragrid. But still the DateTime is in its default format.
//Code
UltraGridColumn.Header.ToolTipText = Field.FieldDescription
UltraGridColumn.Format = "d"
Even after the above format is set the grid shows the value in the column as 06/06/2013 02:43PM
But the expected output is 06/06/2013
Why i'm getting this?
Added the column style as DateTime.
//Code
UltraGridColumn.Style = ColumnStyle.DateTime