Solved

God Damn DataGrids

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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