windows form datagrid questions

W

Wayne

I have a datagrid on my windows form, it needs to be read only and when a
user selects a row, I want the whole row to be selected.

How would I go about doing this?

--
Thanks
Wayne Sepega
Jacksonville, Fl

Enterprise Library Configuration Console Module Generator
http://workspaces.gotdotnet.com/elccmg

"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein
 
G

Guest

Hi Wayne

Interestingly, I've had to do exactly this today. If you start with the
Windows Forms FAQ (at Syncfusion), then that will get you started. I needed
row selection together with ReadOnly data, and also not having the text in
the cell highlighted when I clicked on it, and had to hack it together with a
MouseDown and MouseUp pair of handlers to set the Enable property on the
DataGrid to false, then to true while doing the selection - it felt like a
terrible hack (and I didn't test it much...), and would be interested to see
if other people have a more elegant way of achieving the same thing.

Nigel

private void DataGrid1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
System.Drawing.Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo hti = this.DataGrid1.HitTest(pt);

if(hti.Type == DataGrid.HitTestType.Cell)
{

this.DataGrid1.CurrentCell = new DataGridCell(hti.Row, hti.Column);
this.DataGrid1.Enabled = false;
this.DataGrid1.Select(hti.Row);
this.DataGrid1.Enabled = true;
}

}

private void DataGrid1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
System.Drawing.Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo hti = this.DataGrid1.HitTest(pt);

if(hti.Type == DataGrid.HitTestType.Cell)
{

this.DataGrid1.CurrentCell = new DataGridCell(hti.Row, hti.Column);
this.DataGrid1.Select(hti.Row);
}
}

Here's the code:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Beta 2 News Groups 1
Hiding values in a datagrid 1
///Summary <-- help file generation 2
form inheritance 1
is a char a number? 1
TollBox Pushpin effect 2
New to .net threads 3
DataGrid multi select 3

Top