15,902,777 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 14904307 (Top 11 by date)
Member 14904307
24-Jul-21 17:33pm
View
if the count start by 0 , the count limit for 10 columns is 9, The problem is why the iteration continues after reaching that limit.
Member 14904307
24-Jul-21 17:28pm
View
columncount indicated by the debugger is 10 and columncount-1 is 9 .the limit specified in the block is 9
Member 14904307
24-Jul-21 17:16pm
View
note that when the variable i exceeds the value 9 and takes value 10, the program stops and the message index was out of range.... occurs.Normally the variable i should not exceed the value 9.
Member 14904307
24-Jul-21 17:03pm
View
Dear OriginalGriff, I have used the vs debugger and I found that when the variable i (see in the do while loop block) reached the value 9, the iteration continued instead of to exit the do while loop block as indicated in the block. The variable i continues to iterate ,taking the value 10 that is greater than 9 (limit of the iteration allowed by the block). but why the variable don't stop at the allowed limit of 9 (datagridview1.columncount-1)
Member 14904307
24-Jul-21 15:49pm
View
Dear Richard, I have changed form1.datagridview1 to TrsfDgv1 but the problems persists. There is any problem when transferring data from TrsfDgv1 in form1 to datagridview1 in form2. The problem occurs when running the block Do while ...loop in the last part of the code
Member 14904307
24-Jul-21 15:47pm
View
Dear kreskowiak, I have changed form1.datagridview1 to TrsfDgv1 but the problems persists. There is any problem when transferring data from TrsfDgv1 in form1 to datagridview1 in form2. The problem occurs when running the block Do while ...loop in the last part of the code
Member 14904307
24-Jul-21 5:10am
View
thank you for your advise, i am going to understand about Visual studio debugger and i will tell you after. thanks
Member 14904307
5-May-21 5:47am
View
Now i found the solution. the problem was due to data type in my datagridview. there was type nothing value in some rowcells of datagridview
i added this code : If DataGridView1(j, i).Value IsNot Nothing Then ......end if. so the new code which is working below
Private Sub btnExportToExcel_Click(sender As Object, e As EventArgs) Handles btnExportToExcel.Click
DataGridView1.ReadOnly = True
DataGridView1.AllowUserToAddRows = True
Try
btnExportToExcel.Text = "please wait...."
btnExportToExcel.Enabled = False
SaveFileDialog1.Filter = "Excel document (*.xlsx)|*.xlsx"
If SaveFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim xlApp As Excel.Application
Dim xlWorkbook As Microsoft.Office.Interop.Excel.Workbook
Dim xlWorksheet As Microsoft.Office.Interop.Excel.Worksheet
Dim misvalue As Object = System.Reflection.Missing.Value
Dim i As Integer
Dim j As Integer
xlApp = New Microsoft.Office.Interop.Excel.Application
xlWorkbook = xlApp.Workbooks.Add(misvalue)
xlWorksheet = xlWorkbook.Sheets("sheet1")
For k As Integer = 1 To DataGridView1.Columns.Count
xlWorksheet.Cells(1, k).value = DataGridView1.Columns(k - 1).HeaderText
Next
For i = 0 To DataGridView1.RowCount - 2
For j = 0 To DataGridView1.ColumnCount - 1
If DataGridView1(j, i).Value IsNot Nothing Then
xlWorksheet.Cells(i + 2, j + 1).value = DataGridView1(j, i).Value.ToString
End If
Next
Next
xlWorksheet.SaveAs(SaveFileDialog1.FileName)
xlWorkbook.Close()
xlApp.Quit()
releaseobjectb(xlApp)
releaseobjectb(xlWorksheet)
releaseobjectb(xlWorkbook)
MsgBox("successifully saved" & vbCrLf & "File are saved As:" & SaveFileDialog1.FileName, MsgBoxStyle.Information)
btnExportToExcel.Text = " Export to Ms Excel"
btnExportToExcel.Enabled = False
End If
Catch ex As Exception
MessageBox.Show("Failed to save !!!", "Error message", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
End Sub
Private Sub releaseobjectb(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Finally
GC.Collect()
End Try
End Sub
Member 14904307
3-May-21 17:18pm
View
Yes dear Patrice ,i got "failed to save " error message when i run the code relative to a bound datagridview( dgv obtained by selecting data from a table in database and put them in dataset,...... ). But when the datagridview is not bound , the code is successfully executed
Member 14904307
21-Mar-21 15:46pm
View
Dear Maciej Los , i finally change DataGridView1.Rows(p).Cells(q).Value = "" by DataGridView1.Rows(p).Cells(q).Value = 0 and it works. Apparently it was a problem of data type. Thanks.
Member 14904307
21-Mar-21 14:05pm
View
yes, dear Maciej Los , the datagridview is bound to datasource and datagridview is read only. As you see the code i posted is similar as your's, but i don't understand the source of problem
Show More