Click here to Skip to main content
15,905,073 members
Home / Discussions / C#
   

C#

 
QuestionWhat happoned to System.Uri(string, bool)?? [modified] Pin
Spacix One18-Apr-08 8:36
Spacix One18-Apr-08 8:36 
AnswerRe: What happoned to System.Uri(string, bool)?? Pin
Spacix One18-Apr-08 9:40
Spacix One18-Apr-08 9:40 
QuestionC# SQL Exception Error Pin
hobbsieoz18-Apr-08 8:32
hobbsieoz18-Apr-08 8:32 
AnswerRe: C# SQL Exception Error Pin
Jimmanuel18-Apr-08 9:10
Jimmanuel18-Apr-08 9:10 
GeneralRe: C# SQL Exception Error Pin
hobbsieoz18-Apr-08 20:48
hobbsieoz18-Apr-08 20:48 
GeneralRe: C# SQL Exception Error Pin
Jimmanuel19-Apr-08 2:30
Jimmanuel19-Apr-08 2:30 
QuestionStart a function in application A triggered by application B Pin
pxp18-Apr-08 7:15
pxp18-Apr-08 7:15 
GeneralRe: Start a function in application A triggered by application B Pin
Not Active18-Apr-08 7:31
mentorNot Active18-Apr-08 7:31 
GeneralRe: Start a function in application A triggered by application B Pin
led mike18-Apr-08 11:34
led mike18-Apr-08 11:34 
AnswerRe: Start a function in application A triggered by application B Pin
Judah Gabriel Himango18-Apr-08 8:06
sponsorJudah Gabriel Himango18-Apr-08 8:06 
GeneralRe: Start a function in application A triggered by application B Pin
Spacix One18-Apr-08 8:52
Spacix One18-Apr-08 8:52 
QuestionHow to center the Button through code in the form? Pin
pdoy070818-Apr-08 5:42
pdoy070818-Apr-08 5:42 
AnswerRe: How to center the Button through code in the form? Pin
Charith Jayasundara18-Apr-08 6:16
Charith Jayasundara18-Apr-08 6:16 
GeneralRe: How to center the Button through code in the form? Pin
Charith Jayasundara18-Apr-08 6:19
Charith Jayasundara18-Apr-08 6:19 
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 

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.