How to make the datagrid view not hightlight the first row?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bill

    How to make the datagrid view not hightlight the first row?

    When you retrieve records to diplay in a DataGridView control the first
    record has the background highlighted even though no row is yet selected.
    Does anyone know a way to suppress this first record highlighting after
    pulling the records into the grid?


  • Jack Jackson

    #2
    Re: How to make the datagrid view not hightlight the first row?

    On Sat, 26 Jul 2008 13:35:44 -0600, "bill" <bill@bottlegar den.com>
    wrote:
    >When you retrieve records to diplay in a DataGridView control the first
    >record has the background highlighted even though no row is yet selected.
    >Does anyone know a way to suppress this first record highlighting after
    >pulling the records into the grid?
    >
    Your description isn't quite correct. The first row is in fact
    selected - if you look at DataGridView.Se lectedRows you should see the
    first row in the list.

    I don't know of any way to prevent the first row from being selected.
    You have to arrange to unselect it after the DataGridView selects it.

    If the datagridview is visible at the time you set it's DataSource,
    then calling DataGridView.Cl earSelection() immediately after setting
    the DataSource will most likely work.

    If you are setting the DataSource during the construction of a form
    before the Load event fires, then you may have to call ClearSelection
    later, perhaps in the Form.Load event.

    Comment

    • bill

      #3
      Re: How to make the datagrid view not hightlight the first row?

      The problem I see it that the little chevron doesn't show to the left of the
      highlighted row. It is highlighted but until that chevron is there if you
      try to reference the data set in that row it errors out. I can't seem to
      test for it either.

      "Jack Jackson" <jjackson@cinno vations.netwrot e in message
      news:s06n84lp70 0j189tngvmsh1pu fntg1fhie@4ax.c om...
      On Sat, 26 Jul 2008 13:35:44 -0600, "bill" <bill@bottlegar den.com>
      wrote:
      >
      >>When you retrieve records to diplay in a DataGridView control the first
      >>record has the background highlighted even though no row is yet selected.
      >>Does anyone know a way to suppress this first record highlighting after
      >>pulling the records into the grid?
      >>
      >
      Your description isn't quite correct. The first row is in fact
      selected - if you look at DataGridView.Se lectedRows you should see the
      first row in the list.
      >
      I don't know of any way to prevent the first row from being selected.
      You have to arrange to unselect it after the DataGridView selects it.
      >
      If the datagridview is visible at the time you set it's DataSource,
      then calling DataGridView.Cl earSelection() immediately after setting
      the DataSource will most likely work.
      >
      If you are setting the DataSource during the construction of a form
      before the Load event fires, then you may have to call ClearSelection
      later, perhaps in the Form.Load event.

      Comment

      • Jack Jackson

        #4
        Re: How to make the datagrid view not hightlight the first row?

        I am not sure how you "test for it".

        The DataGridView has two separate things, selected rows (the
        SelectedRows collection) and CurrentRow, the current row. The marker
        in the row header (the left-most column) marks the current row. You
        can change which row is current by setting the CurrentCell property to
        a cell in the row you wish to make current.

        I don't understand what you mean by "if you try to reference the data
        set in that row it errors out". If you get an error, please always
        say what the error is. How are you trying to reference the data?

        On Sun, 27 Jul 2008 00:30:40 -0600, "bill" <bill@bottlegar den.com>
        wrote:
        >The problem I see it that the little chevron doesn't show to the left of the
        >highlighted row. It is highlighted but until that chevron is there if you
        >try to reference the data set in that row it errors out. I can't seem to
        >test for it either.
        >
        >"Jack Jackson" <jjackson@cinno vations.netwrot e in message
        >news:s06n84lp7 00j189tngvmsh1p ufntg1fhie@4ax. com...
        >On Sat, 26 Jul 2008 13:35:44 -0600, "bill" <bill@bottlegar den.com>
        >wrote:
        >>
        >>>When you retrieve records to diplay in a DataGridView control the first
        >>>record has the background highlighted even though no row is yet selected.
        >>>Does anyone know a way to suppress this first record highlighting after
        >>>pulling the records into the grid?
        >>>
        >>
        >Your description isn't quite correct. The first row is in fact
        >selected - if you look at DataGridView.Se lectedRows you should see the
        >first row in the list.
        >>
        >I don't know of any way to prevent the first row from being selected.
        >You have to arrange to unselect it after the DataGridView selects it.
        >>
        >If the datagridview is visible at the time you set it's DataSource,
        >then calling DataGridView.Cl earSelection() immediately after setting
        >the DataSource will most likely work.
        >>
        >If you are setting the DataSource during the construction of a form
        >before the Load event fires, then you may have to call ClearSelection
        >later, perhaps in the Form.Load event.
        >

        Comment

        • Kevin S Gallagher

          #5
          Re: How to make the datagrid view not hightlight the first row?

          Before testing try


          IsNothing(MyDat aGridView.Curre ntRow)



          This should at least stop u from accessing a row that is not valid at the
          current moment in time.







          "bill" <bill@bottlegar den.comwrote in message
          news:%23gJhLJ77 IHA.1196@TK2MSF TNGP05.phx.gbl. ..
          The problem I see it that the little chevron doesn't show to the left of
          the highlighted row. It is highlighted but until that chevron is there if
          you try to reference the data set in that row it errors out. I can't seem
          to test for it either.
          >
          "Jack Jackson" <jjackson@cinno vations.netwrot e in message
          news:s06n84lp70 0j189tngvmsh1pu fntg1fhie@4ax.c om...
          >On Sat, 26 Jul 2008 13:35:44 -0600, "bill" <bill@bottlegar den.com>
          >wrote:
          >>
          >>>When you retrieve records to diplay in a DataGridView control the first
          >>>record has the background highlighted even though no row is yet selected.
          >>>Does anyone know a way to suppress this first record highlighting after
          >>>pulling the records into the grid?
          >>>
          >>
          >Your description isn't quite correct. The first row is in fact
          >selected - if you look at DataGridView.Se lectedRows you should see the
          >first row in the list.
          >>
          >I don't know of any way to prevent the first row from being selected.
          >You have to arrange to unselect it after the DataGridView selects it.
          >>
          >If the datagridview is visible at the time you set it's DataSource,
          >then calling DataGridView.Cl earSelection() immediately after setting
          >the DataSource will most likely work.
          >>
          >If you are setting the DataSource during the construction of a form
          >before the Load event fires, then you may have to call ClearSelection
          >later, perhaps in the Form.Load event.
          >
          >

          Comment

          • bill

            #6
            Re: How to make the datagrid view not hightlight the first row?

            Excellent to know. Thank you!

            "Kevin S Gallagher" <kevin.s.gallag her@state.or.us wrote in message
            news:ObbdEaP8IH A.1428@TK2MSFTN GP06.phx.gbl...
            Before testing try
            >
            >
            IsNothing(MyDat aGridView.Curre ntRow)
            >
            >
            >
            This should at least stop u from accessing a row that is not valid at the
            current moment in time.
            >
            >
            >
            >
            >
            >
            >
            "bill" <bill@bottlegar den.comwrote in message
            news:%23gJhLJ77 IHA.1196@TK2MSF TNGP05.phx.gbl. ..
            >The problem I see it that the little chevron doesn't show to the left of
            >the highlighted row. It is highlighted but until that chevron is there
            >if you try to reference the data set in that row it errors out. I can't
            >seem to test for it either.
            >>
            >"Jack Jackson" <jjackson@cinno vations.netwrot e in message
            >news:s06n84lp7 00j189tngvmsh1p ufntg1fhie@4ax. com...
            >>On Sat, 26 Jul 2008 13:35:44 -0600, "bill" <bill@bottlegar den.com>
            >>wrote:
            >>>
            >>>>When you retrieve records to diplay in a DataGridView control the first
            >>>>record has the background highlighted even though no row is yet
            >>>>selected.
            >>>>Does anyone know a way to suppress this first record highlighting after
            >>>>pulling the records into the grid?
            >>>>
            >>>
            >>Your description isn't quite correct. The first row is in fact
            >>selected - if you look at DataGridView.Se lectedRows you should see the
            >>first row in the list.
            >>>
            >>I don't know of any way to prevent the first row from being selected.
            >>You have to arrange to unselect it after the DataGridView selects it.
            >>>
            >>If the datagridview is visible at the time you set it's DataSource,
            >>then calling DataGridView.Cl earSelection() immediately after setting
            >>the DataSource will most likely work.
            >>>
            >>If you are setting the DataSource during the construction of a form
            >>before the Load event fires, then you may have to call ClearSelection
            >>later, perhaps in the Form.Load event.
            >>
            >>
            >
            >

            Comment

            Working...