Solved

God Damn DataGrids

Posted on 2004-08-19
4
690 Views
Last Modified: 2012-06-27
Howdy!

I'm displaying some records from a database in a DataGrid right?  I don't want the data to be editable, so I've set the ReadOnly field of the DataGrid to true, but the user can still select a cell.  I want the DataGrid to work more like your inbox in Outlook Express, where when you click on a row, the whole row is highlighted, not just a cell.  So I tried this:

private void objTreeGrid_CurrentCellChanged(object sender, System.EventArgs e)
{
      int intRow = objTreeGrid.CurrentRowIndex;
      objTreeGrid.UnSelect(intRow);
      objTreeGrid.Select(intRow);
}

Which kinda works, the whole row becomes selected, but the cell that was clicked also changes into its selected state.  I've tried:

objTreeGrid.CurrentCell = new DataGridCell(-1, -1);

But that just selects the first cell in the first row.  There must be a way to unselect a cell?

Help me, I'm loosing my mind.

LittleCharva
0
Comment
Question by:littlecharva
  • 2
4 Comments
 
LVL 3

Expert Comment

by:bigjim2000
ID: 11839829
Try making your own derrived DataGrid class, and override the OnClick event.  In that event, call the base.OnClick event (if you so desire), then invoke the protected event RowHeaderClick.

If I had more time, I'd do it and send you a sample.... perhaps this will at least get you started.

-Eric
0
 
LVL 21

Expert Comment

by:tovvenki
ID: 11840036
Hi,
In order to select the entire row when the user clicks on a cell in the row just call the DataGrid.Select method from within its mouseup event.
private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
     System.Drawing.Point pt = new Point(e.X, e.Y);
     DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);
     if(hti.Type == DataGrid.HitTestType.Cell)
     {
          dataGrid1.CurrentCell = new DataGridCell(hti.Row, hti.Column);
          dataGrid1.Select(hti.Row);
     }
}
 

Regards,
venki
0
 
LVL 21

Accepted Solution

by:
tovvenki earned 125 total points
ID: 11840054
HI,
have a look at this url http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q856q
I hope that this will help you

Regards,
venki
0
 

Expert Comment

by:exergonic
ID: 14073609
Enough of this syncfusion - it's 50% resourceful.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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