Solved

God Damn DataGrids

Posted on 2004-08-19
4
691 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
[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
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

739 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