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. How to show the datatable values in combobox?

How to show the datatable values in combobox?

Scheduled Pinned Locked Moved C#
helptutorialquestion
2 Posts 2 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.
  • K Offline
    K Offline
    kssknov
    wrote on last edited by
    #1

    hi all i want to show a column value from datatable.I tried as below . it doesnt shows the values. pls help. SqlDataAdapter adpt = new SqlDataAdapter(cmd); DataTable dtCust1 = new DataTable("CustomerDatTab"); adpt.Fill(dtCust1); dataGridView1.DataSource=dtCust1; //datagrid shows data. DataRow dr = new DataRow(); foreach (DataRow dr in dtCust1.Rows) comboBox1.Items.Add(dr.ToString()); //the below code also didnt works. i tried in the below way also //comboBox1.DisplayMember = "CompanyName"; //for (int i = 0; i < dtCust1.Rows.Count - 1; i++) //comboBox1.Items.Add(dtCust1); //comboBox1.DataSource = dtCust1.DefaultView; thank u

    senthil

    J 1 Reply Last reply
    0
    • K kssknov

      hi all i want to show a column value from datatable.I tried as below . it doesnt shows the values. pls help. SqlDataAdapter adpt = new SqlDataAdapter(cmd); DataTable dtCust1 = new DataTable("CustomerDatTab"); adpt.Fill(dtCust1); dataGridView1.DataSource=dtCust1; //datagrid shows data. DataRow dr = new DataRow(); foreach (DataRow dr in dtCust1.Rows) comboBox1.Items.Add(dr.ToString()); //the below code also didnt works. i tried in the below way also //comboBox1.DisplayMember = "CompanyName"; //for (int i = 0; i < dtCust1.Rows.Count - 1; i++) //comboBox1.Items.Add(dtCust1); //comboBox1.DataSource = dtCust1.DefaultView; thank u

      senthil

      J Offline
      J Offline
      Justin Perez
      wrote on last edited by
      #2

      kssknov wrote:

      i want to show a column value from datatable.I tried as below . it doesnt shows the values.

      Yes, you can get values from your DataTable. You could get them from either the DataGridView, or from the DataTable itself I'm just going to show you how to get them from the DataTable. Lets say you want to get all values from a specific column, here's how you would do it:

            for (int rowIndex = 0; rowIndex < yourDataSet.yourDataTable.Rows.Count; rowIndex ++)
            {
              for (int columnIndex = 0; columnIndex < yourDataSet.yourDataTable.Columns.Count; columnIndex ++)
              {
                Console.WriteLine(string.format("Row {0}, Column {1} cell value is {2} !", rowIndex.ToString(),
                   columnIndex.ToString(), yourDataSet.yourDataTable.Rows[rowIndex][columnIndex].ToString())); 
                                                 // for columnIndex you can use the column name if you'd like.
              }
            }
      

      "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")

      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