Solved

God Damn DataGrids

Posted on 2004-08-19
4
687 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Enough of this syncfusion - it's 50% resourceful.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now