Solved

DataGridView adding an image column

Posted on 2008-10-30
5
6,679 Views
Last Modified: 2010-05-18
Hello,

Im currently using the code below to display 4 columns of information. I now want to add a 5th column which will display either a pdf, doc or xls logo depending on the filetype.
How can i adjust my code to do this?
' create a data adapter and a datasource
    Private Sub RetrieveNoticeboard()
 
        Dim dbSourceNew = ConfigurationManager.AppSettings("dbSource")
        Dim objConnection As New SqlConnection("Persist Security Info=False;Initial Catalog=" & _
        "myo;Data Source=" + dbSourceNew + ";User Id=sa;Password=azTbyRqX7c11Q8ZY")
        Dim noticeAdapter As New SqlDataAdapter("SELECT notice_id,notice_date,notice_type,notice_summary" & _
        " FROM noticeboard", objConnection)
        Dim noticeDT As New DataTable("notice")
 
        noticeAdapter.Fill(noticeDT)
        grdNotice.DataSource = noticeDT
 
    End Sub
 
 
 
 
 
 
 
 
 
 
   Private Sub noticeBoard_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
 
        ' list the clients in the datagrid
        RetrieveNoticeboard()
 
        ' setup column headers
        grdNotice.Columns(0).HeaderText = ""
        grdNotice.Columns(0).Visible = False
        grdNotice.Columns(1).HeaderText = "Date"
        grdNotice.Columns(2).HeaderText = "Type"
        grdNotice.Columns(3).HeaderText = "Summary"
        grdNotice.Columns(3).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
        grdNotice.Columns(3).DefaultCellStyle.WrapMode = DataGridViewTriState.True
        grdNotice.Columns(4).HeaderText = "File"
 
 
        ' Update label with number of records
        numRows = grdNotice.BindingContext(grdNotice.DataSource, grdNotice.DataMember).Count
        noticeNo.Text = numRows
 
 
    End Sub
End Class

Open in new window

0
Comment
Question by:drews1f
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 22841281
Displaying an image in gridview field dependant of field value
http://forums.asp.net/p/1022507/1386203.aspx

GridView Examples for ASP.NET 2.0: Displaying Images in a GridView Column
http://msdn.microsoft.com/en-us/library/aa479350.aspx
0
 

Author Comment

by:drews1f
ID: 22841325
my dataTable only has 4 columns though?
Once i have added the 4 columns of data from the ms sql database. How can i add a new column to that datatable?
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 22841377
How to: Add an Unbound Column to a Data-Bound Windows Forms DataGridView Control
http://msdn.microsoft.com/en-us/library/zkatshfa.aspx
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question