Click here to Skip to main content
15,891,734 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to center the Button through code in the form? Pin
Rob Smiley18-Apr-08 6:16
Rob Smiley18-Apr-08 6:16 
GeneralRe: How to center the Button through code in the form? Pin
pdoy070818-Apr-08 6:28
pdoy070818-Apr-08 6:28 
GeneralCrystal Reports Pin
Wikus.Olivier18-Apr-08 5:11
Wikus.Olivier18-Apr-08 5:11 
QuestionLooping Though A DataGridView? Pin
Harvey Saayman18-Apr-08 4:48
Harvey Saayman18-Apr-08 4:48 
AnswerRe: Looping Though A DataGridView? Pin
Justin Perez18-Apr-08 5:05
Justin Perez18-Apr-08 5:05 
GeneralRe: Looping Though A DataGridView? Pin
Harvey Saayman21-Apr-08 0:03
Harvey Saayman21-Apr-08 0:03 
AnswerRe: Looping Though A DataGridView? Pin
Charith Jayasundara18-Apr-08 7:00
Charith Jayasundara18-Apr-08 7:00 
GeneralCombox in datagridview causes exception Pin
AndrusM18-Apr-08 4:31
AndrusM18-Apr-08 4:31 
Run code, press down arrow, up arrow, down arrow.
Invalid operatoin exception occurs.

How to fix ?

Andrus.

using System;<br />
using System.Windows.Forms;<br />
using System.ComponentModel;<br />
<br />
class Supplier {<br />
  public string Id { get; set; }<br />
}<br />
<br />
class Form1 : Form {<br />
  [STAThread]<br />
  static void Main() {<br />
    Application.Run(new Form1());<br />
  }<br />
<br />
  public Form1() {<br />
    DataGridView grid = new DataGridView();<br />
    // if this line is commented out, all is OK:<br />
    grid.EditMode = DataGridViewEditMode.EditOnEnter;<br />
    ComboBoxColumn comboBoxColumn = new ComboBoxColumn();<br />
    ComboBoxCell ComboBoxCell = new ComboBoxCell();<br />
    comboBoxColumn.CellTemplate = ComboBoxCell;<br />
    grid.Columns.Add(comboBoxColumn);<br />
    BindingList<Supplier> l = new BindingList<Supplier>();<br />
    l.Add(new Supplier());<br />
    grid.DataSource = l;<br />
    Controls.Add(grid);<br />
  }<br />
<br />
  class ComboBoxColumn : DataGridViewComboBoxColumn { }<br />
<br />
  class ComboBoxCell : DataGridViewComboBoxCell {<br />
    public override Type EditType {<br />
      get {<br />
        return typeof(ComboBoxEditingControl);<br />
      }<br />
    }<br />
<br />
  }<br />
<br />
  class ComboBoxEditingControl : ComboBox, IDataGridViewEditingControl {<br />
    protected int rowIndex;<br />
    protected DataGridView dataGridView;<br />
    protected bool valueChanged = false;<br />
<br />
    protected override void OnTextChanged(EventArgs e) {<br />
      base.OnTextChanged(e);<br />
      NotifyDataGridViewOfValueChange();<br />
    }<br />
<br />
    protected virtual void NotifyDataGridViewOfValueChange() {<br />
      valueChanged = true;<br />
      if (dataGridView != null) {<br />
        dataGridView.NotifyCurrentCellDirty(true);<br />
      }<br />
    }<br />
<br />
    public Cursor EditingPanelCursor {<br />
      get {<br />
        return Cursors.IBeam;<br />
      }<br />
    }<br />
<br />
    public DataGridView EditingControlDataGridView {<br />
      get {<br />
        return dataGridView;<br />
      }<br />
      set {<br />
        dataGridView = value;<br />
      }<br />
    }<br />
<br />
    public object EditingControlFormattedValue {<br />
      set {<br />
        if (value.ToString() != Text) {<br />
          Text = value.ToString();<br />
          NotifyDataGridViewOfValueChange();<br />
        }<br />
      }<br />
<br />
      get {<br />
        return Text;<br />
      }<br />
    }<br />
<br />
    public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts<br />
    context) {<br />
      return Text;<br />
    }<br />
<br />
<br />
<br />
    public void PrepareEditingControlForEdit(bool selectAll) { }<br />
<br />
    public bool RepositionEditingControlOnValueChange {<br />
      get {<br />
        return false;<br />
      }<br />
    }<br />
<br />
    public int EditingControlRowIndex {<br />
      get {<br />
        return rowIndex;<br />
      }<br />
<br />
      set {<br />
        rowIndex = value;<br />
      }<br />
    }<br />
<br />
    public void ApplyCellStyleToEditingControl(DataGridViewCellStyle<br />
    dataGridViewCellStyle) {<br />
      DropDownStyle = ComboBoxStyle.DropDown;<br />
    }<br />
<br />
    public bool EditingControlWantsInputKey(Keys keyData, bool<br />
    dataGridViewWantsInputKey) {<br />
      return !dataGridViewWantsInputKey;<br />
    }<br />
<br />
    public bool EditingControlValueChanged {<br />
<br />
      get {<br />
        return valueChanged;<br />
      }<br />
      set {<br />
        valueChanged = value;<br />
      }<br />
    }<br />
  }<br />
}


Andrus

GeneralRe: Combox in datagridview causes exception Pin
Justin Perez18-Apr-08 5:07
Justin Perez18-Apr-08 5:07 
GeneralRe: Combox in datagridview causes exception Pin
AndrusM18-Apr-08 5:18
AndrusM18-Apr-08 5:18 
Questionsql server issue Pin
varun.g18-Apr-08 4:26
varun.g18-Apr-08 4:26 
GeneralRe: sql server issue Pin
Charith Jayasundara18-Apr-08 7:05
Charith Jayasundara18-Apr-08 7:05 
Generalappending xml document in C# Pin
mayuri12318-Apr-08 3:37
mayuri12318-Apr-08 3:37 
GeneralRe: appending xml document in C# Pin
led mike18-Apr-08 4:40
led mike18-Apr-08 4:40 
JokeRe: appending xml document in C# Pin
Not Active18-Apr-08 7:33
mentorNot Active18-Apr-08 7:33 
GeneralString.replace("\","\\") never work Pin
cocoonwls18-Apr-08 3:06
cocoonwls18-Apr-08 3:06 
GeneralRe: String.replace("\","\\") never work Pin
Paddy Boyd18-Apr-08 3:08
Paddy Boyd18-Apr-08 3:08 
GeneralRe: String.replace("\","\\") never work Pin
phannon8618-Apr-08 3:19
professionalphannon8618-Apr-08 3:19 
GeneralOr just use @ Pin
Mircea Puiu18-Apr-08 3:35
Mircea Puiu18-Apr-08 3:35 
GeneralRe: String.replace("\","\\") never work Pin
cocoonwls18-Apr-08 3:35
cocoonwls18-Apr-08 3:35 
Question"Real-Time" Audio Manipulation of Microphone Input Pin
littleGiant18-Apr-08 2:11
littleGiant18-Apr-08 2:11 
GeneralLosing object dataGridViewRow.cell.tag after sort Pin
oracleConvert18-Apr-08 2:05
oracleConvert18-Apr-08 2:05 
QuestionHow to working with database, Strongly Typed ? Pin
hdv21218-Apr-08 1:30
hdv21218-Apr-08 1:30 
AnswerRe: How to working with database, Strongly Typed ? Pin
Pete O'Hanlon18-Apr-08 2:33
mvePete O'Hanlon18-Apr-08 2:33 
GeneralRe: How to working with database, Strongly Typed ? Pin
hdv21218-Apr-08 3:37
hdv21218-Apr-08 3:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.