W
Wayne Wengert
I am using VB with a Windows NET application. I have a datagrid in which the
user can add rows using the "*" row. I want to detect whenever the user has
added a row. I found the following code at syncfusion.com but it is in C#
and I am having a problem converting it to VB. If anyone can show the VB
equivalent and/or point me to a better way to detect a row change I'd
appreciate it.
Wayne
===================== Code ===============================
private System.Windows.Forms.DataGrid dataGrid1;
private BindingManagerBase bindingManager;
private void Form1_Load(object sender, System.EventArgs e)
{
// Creating connection and command sting
string conStr = @"Provider=Microsoft.JET.OLEDB.4.0;data
source=C:\northwind.mdb";
string sqlStr = "SELECT * FROM Employees";
// Create connection object
OleDbConnection conn = new OleDbConnection(conStr);
// Create data adapter object
OleDbDataAdapter da = new OleDbDataAdapter(sqlStr,conn);
// Create a dataset object and fill with data using data adapter's Fill
method
DataSet ds = new DataSet();
da.Fill(ds, "Employees");
dataGrid1.DataSource = ds.Tables["Employees"];
bindingManager = this.BindingContext[dataGrid1.DataSource];
bindingManager.PositionChanged += new System.EventHandler(RowChanged);
}
private void RowChanged(object sender, System.EventArgs e)
{
Console.WriteLine("RowChanged " + bindingManager.Position.ToString() );
bool lastRow = bindingManager.Count >
((DataTable)dataGrid1.DataSource).Rows.Count;
if(lastRow)
Console.WriteLine("lastRow");
}
user can add rows using the "*" row. I want to detect whenever the user has
added a row. I found the following code at syncfusion.com but it is in C#
and I am having a problem converting it to VB. If anyone can show the VB
equivalent and/or point me to a better way to detect a row change I'd
appreciate it.
Wayne
===================== Code ===============================
private System.Windows.Forms.DataGrid dataGrid1;
private BindingManagerBase bindingManager;
private void Form1_Load(object sender, System.EventArgs e)
{
// Creating connection and command sting
string conStr = @"Provider=Microsoft.JET.OLEDB.4.0;data
source=C:\northwind.mdb";
string sqlStr = "SELECT * FROM Employees";
// Create connection object
OleDbConnection conn = new OleDbConnection(conStr);
// Create data adapter object
OleDbDataAdapter da = new OleDbDataAdapter(sqlStr,conn);
// Create a dataset object and fill with data using data adapter's Fill
method
DataSet ds = new DataSet();
da.Fill(ds, "Employees");
dataGrid1.DataSource = ds.Tables["Employees"];
bindingManager = this.BindingContext[dataGrid1.DataSource];
bindingManager.PositionChanged += new System.EventHandler(RowChanged);
}
private void RowChanged(object sender, System.EventArgs e)
{
Console.WriteLine("RowChanged " + bindingManager.Position.ToString() );
bool lastRow = bindingManager.Count >
((DataTable)dataGrid1.DataSource).Rows.Count;
if(lastRow)
Console.WriteLine("lastRow");
}