Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 696
  • Last Modified:

God Damn DataGrids

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
littlecharva
Asked:
littlecharva
  • 2
1 Solution
 
bigjim2000Commented:
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
 
tovvenkiCommented:
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
 
tovvenkiCommented:
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
 
exergonicCommented:
Enough of this syncfusion - it's 50% resourceful.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now