Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding DataRow to TextBox

I want to bind textbox to single DataRow object (passed to dialog form for editing). Here is my code:

DataRow row = myDataTable.NewRow();
EditForm form = new EditForm(row);

//in EditForm constructor
nameTextBox.DataBindings.Add("Text", row, "name");

and I'm gettinh an error: Cannot bind to property or column in DataSource. Do you know what I'm missing or any workarounds maybe?

[Added]

My DataTable for sure contains DataColumn with ColumnName="name". Here is my code for creating DataTable

    public DataTable SelectReturnDataTable(string tableName, string sql, params SQLiteParameter[] parameters)
    {
        using (SQLiteConnection conn = new SQLiteConnection(_connectionString))
        {
            using (SQLiteCommand cmd = new SQLiteCommand(conn))
            {
                cmd.CommandText = sql;
                foreach (SQLiteParameter p in parameters)
                    cmd.Parameters.Add(p);

                SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
                DataTable dt = new DataTable(tableName);                                        

                conn.Open();                    
                da.Fill(dt);

                return dt;
            }
        }
    }
like image 533
Adrian Serafin Avatar asked Mar 16 '10 22:03

Adrian Serafin


1 Answers

Try this:

DataView dv = myDataTable.DefaultView;

dv.RowFilter = "id=1";

nameTextBox.DataBindings.Add("Text",dv,"NAME");
like image 193
Kavin Avatar answered Oct 14 '22 19:10

Kavin