Click here to Skip to main content
16,013,489 members
Home / Discussions / C#
   

C#

 
GeneralRe: Automatic printing to pdf Pin
sverre.andersen19-Oct-04 10:28
sverre.andersen19-Oct-04 10:28 
GeneralRe: Automatic printing to pdf Pin
sverre.andersen21-Oct-04 0:57
sverre.andersen21-Oct-04 0:57 
GeneralRe: Automatic printing to pdf Pin
Heath Stewart21-Oct-04 6:23
protectorHeath Stewart21-Oct-04 6:23 
GeneralRe: Automatic printing to pdf Pin
sverre.andersen4-Nov-04 0:06
sverre.andersen4-Nov-04 0:06 
GeneralRe: Automatic printing to pdf Pin
Heath Stewart4-Nov-04 4:55
protectorHeath Stewart4-Nov-04 4:55 
GeneralComboboxes with relations in a datagrid Pin
jalla7214-Oct-04 0:44
jalla7214-Oct-04 0:44 
GeneralRe: Comboboxes with relations in a datagrid Pin
Heath Stewart14-Oct-04 6:46
protectorHeath Stewart14-Oct-04 6:46 
GeneralRe: Comboboxes with relations in a datagrid Pin
jalla7214-Oct-04 20:04
jalla7214-Oct-04 20:04 
Hello again. It isn't a third-part component, but i've found the solution on another forum. The ComboTextCol.ColumnComboBox code looks like this:

public class DataGridComboBoxColumn : DataGridTextBoxColumn
{
public NoKeyUpCombo ColumnComboBox;
private System.Windows.Forms.CurrencyManager _source;
private int _rowNum;
private bool _isEditing;
public static int _RowCount;

public DataGridComboBoxColumn() : base()
{
_source = null;
_isEditing = false;
_RowCount = -1;

ColumnComboBox = new NoKeyUpCombo();
ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDownList;

ColumnComboBox.Leave += new EventHandler(LeaveComboBox);
// ColumnComboBox.Enter += new EventHandler(ComboMadeCurrent);
ColumnComboBox.SelectionChangeCommitted += new EventHandler(ComboStartEditing);

}
private void ComboStartEditing(object sender, EventArgs e)
{
_isEditing = true;
base.ColumnStartedEditing((Control) sender);
}

private void HandleScroll(object sender, EventArgs e)
{
if(ColumnComboBox.Visible)
ColumnComboBox.Hide();

}
// private void ComboMadeCurrent(object sender, EventArgs e)
// {
// _isEditing = true;
// }
//
private void LeaveComboBox(object sender, EventArgs e)
{
if(_isEditing)
{
SetColumnValueAtRow(_source, _rowNum, ColumnComboBox.Text);
_isEditing = false;
Invalidate();
}
ColumnComboBox.Hide();
this.DataGridTableStyle.DataGrid.Scroll -= new EventHandler(HandleScroll);

}


protected override void Edit(System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
{


base.Edit(source,rowNum, bounds, readOnly, instantText , cellIsVisible);

_rowNum = rowNum;
_source = source;

ColumnComboBox.Parent = this.TextBox.Parent;
ColumnComboBox.Location = this.TextBox.Location;
ColumnComboBox.Size = new Size(this.TextBox.Size.Width, ColumnComboBox.Size.Height);
ColumnComboBox.SelectedIndex = ColumnComboBox.FindStringExact(this.TextBox.Text);
ColumnComboBox.Text = this.TextBox.Text;
this.TextBox.Visible = false;
ColumnComboBox.Visible = true;
this.DataGridTableStyle.DataGrid.Scroll += new EventHandler(HandleScroll);

ColumnComboBox.BringToFront();
ColumnComboBox.Focus();
}

protected override bool Commit(System.Windows.Forms.CurrencyManager dataSource, int rowNum)
{

if(_isEditing)
{
_isEditing = false;
SetColumnValueAtRow(dataSource, rowNum, ColumnComboBox.Text);
}
return true;
}

protected override void ConcedeFocus()
{
Console.WriteLine("ConcedeFocus");
base.ConcedeFocus();
}

protected override object GetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, int rowNum)
{

object s = base.GetColumnValueAtRow(source, rowNum);
DataView dv = (DataView)this.ColumnComboBox.DataSource;
int rowCount = dv.Count;
int i = 0;

//if things are slow, you could order your dataview
//& use binary search instead of this linear one
while (i < rowCount)
{
if( s.Equals( dv[i][this.ColumnComboBox.ValueMember]))
break;
++i;
}

if(i < rowCount)
return dv[i][this.ColumnComboBox.DisplayMember];

return DBNull.Value;
}

protected override void SetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, int rowNum, object value)
{
object s = value;

DataView dv = (DataView)this.ColumnComboBox.DataSource;
int rowCount = dv.Count;
int i = 0;

//if things are slow, you could order your dataview
//& use binary search instead of this linear one
while (i < rowCount)
{
if( s.Equals( dv[i][this.ColumnComboBox.DisplayMember]))
break;
++i;
}
if(i < rowCount)
s = dv[i][this.ColumnComboBox.ValueMember];
else
s = DBNull.Value;
base.SetColumnValueAtRow(source, rowNum, s);

}

}

public class NoKeyUpCombo : ComboBox
{
private const int WM_KEYUP = 0x101;

protected override void WndProc(ref System.Windows.Forms.Message m)
{
if(m.Msg == WM_KEYUP)
{
m.Result = System.IntPtr.Zero;
//ignore keyup to avoid problem with tabbing & dropdownlist;
return;
}

base.WndProc(ref m);
}

}

And I access it like this:

ComboTextCol = new DataGridComboBoxColumn();

Do you know a better way to get a combobox in a datagrid??
GeneralRe: Comboboxes with relations in a datagrid Pin
Heath Stewart14-Oct-04 20:14
protectorHeath Stewart14-Oct-04 20:14 
GeneralRe: Comboboxes with relations in a datagrid Pin
jalla7215-Oct-04 0:01
jalla7215-Oct-04 0:01 
GeneralRe: Comboboxes with relations in a datagrid Pin
Heath Stewart15-Oct-04 6:18
protectorHeath Stewart15-Oct-04 6:18 
QuestionHow to make the Form (at run time) behave like the Form (at design time) Pin
god4k14-Oct-04 0:33
god4k14-Oct-04 0:33 
AnswerRe: How to make the Form (at run time) behave like the Form (at design time) Pin
Heath Stewart14-Oct-04 6:50
protectorHeath Stewart14-Oct-04 6:50 
AnswerRe: How to make the Form (at run time) behave like the Form (at design time) Pin
Christian Wikander15-Oct-04 3:32
Christian Wikander15-Oct-04 3:32 
GeneralMoving a file over a network. Pin
Dylan van Heerden14-Oct-04 0:30
Dylan van Heerden14-Oct-04 0:30 
GeneralRe: Moving a file over a network. Pin
Colin Angus Mackay14-Oct-04 2:00
Colin Angus Mackay14-Oct-04 2:00 
GeneralRe: Moving a file over a network. Pin
Dylan van Heerden14-Oct-04 2:18
Dylan van Heerden14-Oct-04 2:18 
GeneralRe: Moving a file over a network. Pin
Colin Angus Mackay14-Oct-04 2:22
Colin Angus Mackay14-Oct-04 2:22 
GeneralRe: Moving a file over a network. Pin
Dylan van Heerden14-Oct-04 2:39
Dylan van Heerden14-Oct-04 2:39 
GeneralRe: Moving a file over a network. Pin
Colin Angus Mackay14-Oct-04 2:47
Colin Angus Mackay14-Oct-04 2:47 
GeneralRe: Moving a file over a network. Pin
Dylan van Heerden14-Oct-04 2:51
Dylan van Heerden14-Oct-04 2:51 
GeneralRe: Moving a file over a network. Pin
Heath Stewart14-Oct-04 6:43
protectorHeath Stewart14-Oct-04 6:43 
GeneralRe: Moving a file over a network. Pin
Heath Stewart14-Oct-04 6:38
protectorHeath Stewart14-Oct-04 6:38 
GeneralStrong name to Interop assembly Pin
hatim_ali13-Oct-04 23:44
hatim_ali13-Oct-04 23:44 
GeneralRe: Strong name to Interop assembly Pin
Alex Korchemniy14-Oct-04 9:18
Alex Korchemniy14-Oct-04 9:18 

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.