DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2004
    Posts
    89

    Question Datagridview - adding combobox

    Hi,
    I have a datagridview in my windows application to which i have to add combo box to a column. Combo box in each row will have different datasource based on the values in the other columns of the same row. I tried with the following code.

    DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn();
    col.HeaderText = "Test";
    col.DataSource = ds.Tables[0];
    col.DisplayMember = ds.Tables[0].Columns[0].ToString();
    col.ValueMember = ds.Tables[0].Columns[0].ToString();
    col.DefaultCellStyle.NullValue = ds.Tables[0].Rows[0][0].ToString();
    col.FlatStyle = FlatStyle.Flat;

    dataGridView1.AllowUserToAddRows = false;
    col.DisplayIndex = ds.Tables[0].Columns.Count + 1;
    dataGridView1.DataSource = ds.Tables[0].DefaultView;

    dataGridView1.Columns.Add(col);

    But i need to bind a different datasource for each combobox column. Kindly let me know. Its very urgent. Any help would be appreciated.

    Thank You,
    Hari
    ----------------
    Hariharan B

  2. #2
    Join Date
    Aug 2007
    Location
    London
    Posts
    73
    You can give on the <asp:datagrid onitemdatabound="call_value" .../>

    in the code behind write like...

    Code:
     Public Sub call_value(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
       Dim combo As Combobox = CType(e.Item.FindControl("comb_name"), Combobox)
    If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
    
    Write a function to bind data to the combo box
    select Name from table1 where place='abc'
    
    end if
    this will slove ur problem...i think

  3. #3
    Join Date
    Nov 2004
    Posts
    89
    Its Not WEB Application, I need this on Windows Application.

    Thanks
    Hari
    ----------------
    Hariharan B

  4. #4
    Join Date
    Aug 2007
    Location
    London
    Posts
    73
    oops sorry i didn't see its for windows application.....

    i don't have much exp in windows application...will try something...if i get something..will post here...

Similar Threads

  1. Replies: 0
    Last Post: 07-08-2007, 06:38 PM
  2. Adding ComboBox to a bound DataGridView
    By camrontucker in forum .NET
    Replies: 2
    Last Post: 03-10-2007, 12:02 PM
  3. DatagridView combobox
    By NXSA in forum .NET
    Replies: 0
    Last Post: 07-31-2006, 04:57 PM
  4. ComboBox - adding item data
    By Mike in forum .NET
    Replies: 1
    Last Post: 03-27-2002, 05:05 PM
  5. Adding item to combobox
    By Eray Sazan in forum Web
    Replies: 0
    Last Post: 03-22-2001, 07:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links