locked
DataBinding, DataTable and DataColumn questions RRS feed

  • Question

  • Hi all, i have a few quetion to discover, bee so pleasant to explain me how i can do:


    1)
    I have combobox and data source for one


    this.comboBox1.DataSource = this.authorsBindingSource;


    Now I need to add to combobox an row, what not exist in bindingSource (supoose I want do display in combobox an additional row "not defined")
    How I can do this????
    ---------------------------------------------------------------
    2)
    How I can to mark a rows in dataTable, so that ones not will be stored in database then this dataTable updated.
    I mean:


    //myDataTable - DataTable object

    // I want that this row shouldn’t bee stored in database, but exist in //dataTable (what I should do)
    DataRow dr1 = myDataTable.NewRow();

    ///initilize row columns with data
    ..


    myDataTable.Rows.Add(dr1);


    // I want that this row should bee stored in database and exist in //dataTable (rest all as is)
    DataRow dr2 = myDataTable.NewRow();

    ///initilize row columns with data
    ..


    myDataTable.Rows.Add(dr2);

    //Want to bee stored dr2 not dr1
    this.myDataTableAdapter.Update(myDataTable);


    How I can do this.
    -----------------------------------------------------------------------------------
    3) How I can explore what column (DataColumn type) have default value???
    Monday, February 19, 2007 2:38 PM

Answers

  • 1). To add an item in a bound ComboBox, you have to add a row into the table in your bindingSource. You could not add it directly by statements like ComboBox1.Items.Add();

    2). For your 2nd question.If you don't want to save dr1,just temporarily remove it from myDataTable in your saving process, and at the end of the process, add it to myDataTable again.

    3) For a datatable column, there's a  DefaultValue property for you to set the default value.For example: dataTable1.Columns[0].DefaultValue
    Thursday, March 1, 2007 8:12 AM