?
Solved

Remove cell highlighting for datagridview

Posted on 2009-05-18
5
Medium Priority
?
2,571 Views
Last Modified: 2012-05-07
Hi Experts,

I have a datagridview. When I click on a cell it highlights with the highlight color. I have tried to disable this by using clearselection(). However it still shows just for the mouse down event. I tried to use the following:

dgvInvoices.CurrentCell.Selected = False

This didnt work...

Any ideas??

Simon
0
Comment
Question by:si2030
[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
  • 2
5 Comments
 
LVL 9

Expert Comment

by:CyberLex
ID: 24412359
maybe this is what you are looking for ... see screenshots :)

cheers
Lex
step1.gif
step2.gif
0
 

Author Comment

by:si2030
ID: 24412625
Hi Lex,

I have created the DGV programmatically and didnt use the option you have displayed above..

I am applying a binding source via code. I have included the full sub below.

There must be an easy way to drive this... I also tried to set the background selection color to white but that also didnt work...

Simon
Public Sub displayFoundInvoices(ByVal openInvoices As Object)
 
        Try
 
            Dim imgSelectAsset As New DataGridViewImageColumn
            imgSelectAsset.ImageLayout = DataGridViewImageCellLayout.Normal
            imgSelectAsset.Image = My.Resources.empty_16
 
            
            'Set up the bindingsource.
            Dim bs As New BindingSource()
 
            With dgvInvoices
 
                'Set the DGV to not allow the user to add rows, delete rows and resize rows.
                'They can resize columns as this was not set and defaults TRUE.
                .AllowUserToAddRows = False
                .AllowUserToDeleteRows = False
                .AllowUserToResizeRows = False
                '.SelectionMode = DataGridViewSelectionMode.FullRowSelect
 
                'Force the column header height to be 20.
                .ColumnHeadersHeight = 20
 
                'Centre the row headings.
                .ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
 
                If loadedAgain = False Then
 
                    'Add the image column to the DataGridView control.
                    .Columns.Add(imgSelectAsset)
 
                    imgSelectAsset.Name = "imgSelectAsset"
 
                    .Columns("imgSelectAsset").ReadOnly = True
                    .Columns("imgSelectAsset").HeaderText = "Pay Now"
 
                End If
 
                'Simply add the data returned from the PRESENTER to the datagridview.
                bs.DataSource = openInvoices
                .DataSource = bs
 
                'FINISH THE RENDER OF THE DGV.
 
                'Remove row headers for the datagridview.
                .RowHeadersVisible = False
 
                'Set the row headings to something more readable.
                .Columns("ref1").HeaderText = "Invoice No"
                .Columns("tran_date").HeaderText = "Transaction Date"
                .Columns("client_no").HeaderText = "Client No"
                .Columns("name").HeaderText = "Name"
                .Columns("amount").HeaderText = "Invoice Total"
                .Columns("balance").HeaderText = "Balance Left to Pay"
 
                'Set all but the last column to readonly.
                .Columns("imgSelectAsset").ReadOnly = True
                .Columns("ref1").ReadOnly = True
                .Columns("tran_date").ReadOnly = True
                .Columns("client_no").ReadOnly = True
                .Columns("name").ReadOnly = True
                .Columns("amount").ReadOnly = True
                .Columns("balance").ReadOnly = True
 
                'Make the posting column invisible
                .Columns("posting_id").Visible = False
 
                If loadedAgain = False Then
 
                    'Add the apply column to the DataGridView control.
                    .Columns.Add("apply", "Payment Applied")
 
                    'Add image test column.
                    .Columns.Add("imageTest", "Image Test")
                    .Columns("imageTest").Visible = False
 
                End If
 
                'Set each column's respective width.
                .Columns("imgSelectAsset").Width = 40
                .Columns("tran_date").Width = 100
                .Columns("ref1").Width = 80
                .Columns("client_no").Width = 80
                .Columns("name").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
                .Columns("balance").Width = 90
                .Columns("amount").Width = 90
                .Columns("apply").Width = 90
 
                .Columns("tran_date").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .Columns("ref1").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
                .Columns("client_no").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .Columns("name").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
                .Columns("amount").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("balance").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("apply").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
 
                .ClearSelection()
 
            End With
 
            loadedAgain = True
 
        Catch ex As Exception
 
            manageWindowsViewError("creditorTASK", "frmCreditorInvoicePayment", "displayFoundInvoices", ex)
 
        End Try
 
    End Sub

Open in new window

0
 
LVL 9

Accepted Solution

by:
CyberLex earned 2000 total points
ID: 24414182
Greetings

this did work for me, altough I did not bind to datasource, don't know if it behaves differently if done so. Need to do this for each column.

:)
Lex
Dim mystyle As New DataGridViewCellStyle
 
mystyle.SelectionBackColor = Color.White
mystyle.SelectionForeColor = Color.White
 
Column1.DefaultCellStyle = mystyle

Open in new window

0
 
LVL 4

Expert Comment

by:barrislb
ID: 24420024
Hi si2030

Have you tried this? I hope this be some help to your need.

 Private Sub dgvInvoices_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgvInvoices.CellMouseClick
    If e.Button = MouseButtons.Left Then
       dgvInvoices.CurrentCell = Nothing
   End If
 End Sub
0
 

Author Closing Comment

by:si2030
ID: 31582601
This worked thanks.... appreciated
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month15 days, 5 hours left to enroll

770 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