Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. why the DataGridViewComboBoxColumn values are lost?!!!

why the DataGridViewComboBoxColumn values are lost?!!!

Scheduled Pinned Locked Moved C#
debugginghelptutorialquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Elvia Gonzalez
    wrote on last edited by
    #1

    Hi everybody! I have DataGridView whose sourse I set to a datatable with 4 columns containing data. I then remove two columns, create a DataGridViewComboBoxColumn and DataGridViewCheckBoxColumn and insert this into the same location as the columns that were removed. I want to set as the selected value in the combo box of every cell in the DataGridView a specific value. I have done it, but once the debugger leaves the file with the code that executes this functionality, the values that were set in the combo box and check box are lost. I don't know whether the problem is because I removed and then added these columns. At the end of the Load() method I have this line: dataGridView.AutoGenerateColumns = false; if I don't use it, the column that I removed appears again. Any idea about why the value of the DataGridComboBoxColumn is changed to null automatically and how to solve it? Other thing is that if I change the values of the combo box in the datagridview and later I want to save them, when I get the values are not the ones I chose, but the values that I set at the beginning as the datasource of the datagridview. This is part of the code I’m using: private void FrmTestCases_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Path", typeof(string))); dt.Columns.Add(new DataColumn("Category", typeof(string))); dt.Columns.Add(new DataColumn("Include", typeof(string))); dt.Columns.Add(new DataColumn("Description", typeof(string))); dataGridView.DataSource = dt; dataGridView.Columns.Remove("Category"); dataGridView.Columns.Remove("Include"); DataGridViewComboBoxColumn cb = new DataGridViewComboBoxColumn(); DataGridViewCheckBoxColumn kb = new DataGridViewCheckBoxColumn(); cb = CreateComboBoxColumn("Category", "Category"); kb = CreateCheckBoxColumn("Include", "Include"); dataGridView.Columns.Insert(1, cb); dataGridView.Columns.Insert(2, kb); } // --------- private void OnFormClosing(object sender, FormClosingEventArgs e) { DataRowView testCase = (DataRowView)dataGridView.Rows[0].DataBoundItem; String fileStream = testCase["Include"] + "," + testCase["Category"]; } I've been working on it for days but NO LUCK !! Can you please give me a hand?! Elvia

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups