c# - DataGridColumn Change to ComboBox -


i have list usrdetails i'm using data source datagridview. 2 questions:

  1. how can change column type 3rd column in datagridview datagridtextboxcolumn datagridcomboboxcolumn?

  2. once i've changed 3rd column combobox how populate list of strings?


public class usrinfo {     public string userid { get; set; }     public string username { get; set; }     public string group { get; set; }     public string seclev { get; set; }     public string isext { get; set; }      public usrinfo(string userid, string username, string group, string seclev, string isext)     {         this.userid = userid;         this.username = username;         this.group = group;         this.seclev = seclev;         this.isext = isext;     } }  public static list<usrinfo> usrdetails = new list<usrinfo>();  private void form5_load(object sender, eventargs e) {     var combocolumn = new datagridviewcomboboxcolumn();           datagridview1.datasource = null;         datagridview1.datasource = usrdetails;         (int = 0; < secgrps.count; i++)           groups.add(secgrps[i].tostring());         combocolumn.name ="security group";         combocolumn.datasource = groups;         datagridview1.columns.insert(2, combocolumn);         usrdetails.add(new usrinfo("domain\\userid", "user name", "rigsite wellsite leader", "7", "y"));         datagridview1.refresh();         if (usrdetails.count > -1)             num_users = true;  } 

you need add datagridviewcomboboxcolumn datagridview1 control , assign datasource property collection of strings want.

var mystringcollection = new[] {"string1", "string2", "string3"};  var combocolumn = new datagridviewcomboboxcolumn(); combocolumn.name = "mycombocolumn"; combocolumn.datasource = mystringcollection; //this sets source of drop down items 

then insert grid:

if (datagridview1.columns["mycombocolumn"] == null) {     //the int value first parameter of insert() desired column index     datagridview1.columns.insert(0, combocolumn); } 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -