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
A

aerinai

@aerinai
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • DataGridView with ComboBox. Need help
    A aerinai

    I have been wracking my brain for hours on this problem. I have a DataGridView object that has a DataGridViewComboBoxColumn inside of it. The combo box displays fine and is populated from an Access database. The column has the Primary key mapped to the ValueMember variable and the column 'Type' is mapped to DisplayMember. What I need is for each of these combo boxes to have their selected index (I think it is the Value property under DataGridViewComboBoxCell, but I'm pulling at straws at this point) be populated from another table. This took me about 6 seconds in Access. My problem is I cannot even find a way to access the Value/SelectedIndex of the Combobox once I place it in the DataGridView. If anyone could help me out I'd greatly appreciate it. Here is the code:

        //Connection string to DB.
        OleDbConnection dbCon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\"" + "NGDemoSetup.mdb" + "\\"");
    
        //Dataset for majority of data
        DataSet ds = new DataSet();
    
        //Dataset for the combobox
        DataSet cboDs = new DataSet();
    
        //Create a DGVComboBoxColumn to hold the Types we have in the ADDRESSTYPES Table of the DB.
        DataGridViewComboBoxColumn cboCol = new DataGridViewComboBoxColumn();
    
        //Open the DB.
        dbCon.Open();
    
        //Grab all the data we need from the Location Info table 
        OleDbDataAdapter da = new OleDbDataAdapter("SELECT AddrType,isRange,Value1,Value2 FROM LOCATIONINFO", dbCon);
    
        //Grab all the columns from ADDRESSTYPES (ID and Types).
        OleDbDataAdapter cboDa = new OleDbDataAdapter("SELECT \* FROM ADDRESSTYPES", dbCon);
    
        da.Fill(ds, "LocationInfo");
        cboDa.Fill(cboDs, "AddressTypes");
    
        cboCol.Width = 100;
        cboCol.DataSource = cboDs.Tables\[0\];
        
        cboCol.ValueMember = "ID";
        cboCol.DisplayMember = "Type";
        DataTable dt = ds.Tables\["LocationInfo"\];
       
        grdAddressInfo.DataSource = dt;
    
        /\*
         \* Somehow make the ComboBox Column display the correct Dropdown object
         \* Based upon the AddrType field.
         \*/
    
        //Column formatting
        grdAddressInfo.Columns.Insert(0, cboCol);
        grdAddressInfo.Columns\[0\].HeaderText = "Address Type";
        grdAddressInfo.Columns\[1\].HeaderText = "Ranged Value";
        grdAddressInfo.Columns\[2\].HeaderText = "From";
        grdAddressInfo.Columns\[3\].HeaderText = "To";
    
        dbCon.Close();
    
    C# database help
  • Login

  • Don't have an account? Register

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