Questions re DataGrid

  • Thread starter Thread starter Jeff Cook
  • Start date Start date
J

Jeff Cook

Hi

1. In a DataGrid, I'd like to respond to a click anywhere on the line,
but it seems that the click event only works on the first column (the
"indicator" column).

2. In my click event, I want to get data from the correct row of the
DataSet (XML). This what I've done so far, and I realise that I have
specifically asked for row zero, but I can't see how to specify the
"current" row.

private void grdLandlords_Click(object sender, System.EventArgs e)
{
frmLandlord f = new frmLandlord();
f.Text = "Landlord "
+ (string) ds.Tables["Landlord"].Rows[0]["LandlordCode"]
+ " "
+ (string) ds.Tables["Landlord"].Rows[0]["SortKey"];
f.Show();
} // eventually, I'll pass the LandlordCode and assign f.Text from within
the form - if I can work out how to access my main form DataSet!

TIA

Jeff
 
Hi Jeff,
1. In a DataGrid, I'd like to respond to a click anywhere on the line,
but it seems that the click event only works on the first column (the
"indicator" column).

Play with the MouseDown/MouseUp events. These work OK for me.
2. In my click event, I want to get data from the correct row of the
DataSet (XML). This what I've done so far, and I realise that I have
specifically asked for row zero, but I can't see how to specify the
"current" row.

CurrencyManager cm = (CurrencyManager)theForm.BindingContext[
theGrid.DataSource, theGrid.DataMember];

DataView theView = (DataView)cm.List;
DataRow currentRow = theView[cm.Current].Row;

Hope this helps.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Jeff Cook said:
Hi

1. In a DataGrid, I'd like to respond to a click anywhere on the line,
but it seems that the click event only works on the first column (the
"indicator" column).

2. In my click event, I want to get data from the correct row of the
DataSet (XML). This what I've done so far, and I realise that I have
specifically asked for row zero, but I can't see how to specify the
"current" row.

private void grdLandlords_Click(object sender, System.EventArgs e)
{
frmLandlord f = new frmLandlord();
f.Text = "Landlord "
+ (string) ds.Tables["Landlord"].Rows[0]["LandlordCode"]
+ " "
+ (string) ds.Tables["Landlord"].Rows[0]["SortKey"];
f.Show();
} // eventually, I'll pass the LandlordCode and assign f.Text from within
the form - if I can work out how to access my main form DataSet!

TIA

Jeff
 
Back
Top