Wednesday 15 September 2010

winforms - Unable to populate a DataGridViewComboBoxColumn created at design time -


I have a DataGridWive Columbobox column in design time. But I want to regulate it on runtime. But this is not happening.

This is the full code

  Public Partial Category Form 1: Form {Private List & lt; FileInformation & gt; FileInformationList; Public Form 1 () {Initialization (); PrepareGrid (); DisplayResult (); } Private void PrepareGrid () {var fileNameColumn = new DataGridViewTextBoxColumn {Name = @ "filename", HeaderText = "filename", DataPropertyName = @ "filename", AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, ReadOnly = false, frozen = false} ; DataGridView1.Columns.Add (fileNameColumn); Var downloadColumn = new DataGridViewLinkColumn {Name = @ "Download", HeaderText = @ "Download", DataPropertyName = @ "Download", AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, ReadOnly = true}; DataGridView1.Columns.Add (downloadColumn); Var dropdownColumn = new DataGridViewComboBoxColumn {Name = @ "Test", HeaderText = @ "country", AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, ReadOnly = true}; DataGridView1.Columns.Add (dropdownColumn); } Private Zero Performance Display () {FileInformationList = LoadItems (); DataGrid View1.DataSource = FileInformationList; ((Datagrid Weave ComboBox column) DataGrid view 1. Column ["Test"]). Data source = GetCountryList (); ((Datagrid Weigh combo box column) Datagram view 1. Column ["Test"]). ValueMember = "id"; ((Datagrid Weigh combo box column) Datagram view 1. Column ["Test"]). Exhibition = "name"; } Private listing & lt; FileInformation & gt; Loaded Items () {var lstScriptInfo = New list & lt; File notification & gt; (); For (Int i = 1; i & lt; = 5; i ++) {lstScriptInfo.Add (new file information {FileName = "file" + i.ToString () + ".txt"}); } Return lstScriptInfo; } Private Datatable GetCountryList () {DataTable CountryDt = New DataTable (); CountryDt.Columns.Add ("id"); CountryDt.Columns.Add ("name"); Add Country Warrant ("1", "Canada"); Addicted. Add. ("2", "USA"); Return country; }} Public Square FileInformation {public string fileName {get; Set; } Public string download {get {return "download file"; }}}}   

is output

enter Image description here

Please help me identify what went wrong?

There are two ways to get:

  1. Default Zero Value Installation for columns (left out of zero checks):

      on cbColumn = (DataGridViewComboBoxColumn) dataGridView1. Column ["test"]; Var ds = GetCountryList (); CbColumn.DataSource = DS; CbColumn.ValueMember = "id"; CbColumn.DisplayMember = "name"; CbColumn.DefaultCellStyle.NullValue = ds.Rows [0] [0]; CbColumn.DefaultCellStyle.DataSourceNullValue = ds.Rows [0] [1];  
  2. To repeat after second DataBinding and install it manually:

      private void DataGridDataBindingComplete (object sender, DataGridViewBindingCompleteEventArgs e) {foreach (DataGridViewRow line dataGridView1.Rows) {var hasValue = row.Cells [ "Test"] values ​​= null .; If (! Bhabhi) {row.Cells ["Test"]. Value = 1; }}}     

    I also binding order Bdlunga:

      private void Pradrshnpratifl () {var cbColumn = (DataGridViewComboBoxColumn) DataGridView1.Columns ["Test"]; Var ds = GetCountryList (); CbColumn.DataSource = DS; CbColumn.ValueMember = "id"; CbColumn.DisplayMember = "name"; CbColumn.DefaultCellStyle.NullValue = ds.Rows [0] [0]; CbColumn.DefaultCellStyle.DataSourceNullValue = ds.Rows [0] [1]; File information notification = load item (); DataGrid View1.DataSource = FileInformationList; }    

No comments:

Post a Comment