Click here to Skip to main content
15,920,438 members
Home / Discussions / C#
   

C#

 
GeneralRe: client server problem Pin
Polis Pilavas10-Apr-05 7:50
Polis Pilavas10-Apr-05 7:50 
GeneralDrawing a 2D matrice of double values Pin
israeli9-Apr-05 2:15
israeli9-Apr-05 2:15 
GeneralRe: Drawing a 2D matrice of double values Pin
Dave Kreskowiak9-Apr-05 5:54
mveDave Kreskowiak9-Apr-05 5:54 
GeneralRe: Drawing a 2D matrice of double values Pin
israeli9-Apr-05 8:32
israeli9-Apr-05 8:32 
GeneralRe: Drawing a 2D matrice of double values Pin
leppie9-Apr-05 9:51
leppie9-Apr-05 9:51 
Generalreading XML Files..... Pin
Imran Adam9-Apr-05 2:07
Imran Adam9-Apr-05 2:07 
GeneralRe: reading XML Files..... Pin
DavidNohejl9-Apr-05 2:16
DavidNohejl9-Apr-05 2:16 
GeneralAutoComplete Combobox in datagrid Pin
Bedevian9-Apr-05 1:43
Bedevian9-Apr-05 1:43 
hi can anyone help me to append this code, to have autocomplete combobox in datagrid ?

using System;
using System.Windows.Forms;
using System.Drawing;
using System.Data;
using System.Diagnostics;


namespace Stock
{
// Derive class from DataGridTextBoxColumn
public class DataGridComboBoxColumnNAME : DataGridTextBoxColumn
{
// Hosted ComboBox control
// private AutoCompleteComboBoxNAME comboBox;
private ComboBox comboBox;
private CurrencyManager cm;
private int iCurrentRow;






// Constructor - create combobox, register selection change event handler,
// register lose focus event handler
public DataGridComboBoxColumnNAME()
{
this.cm = null;

// Create ComboBox and force DropDownList style
this.comboBox = new ComboBox();
this.comboBox.DropDownStyle = ComboBoxStyle.DropDown;

this.comboBox.Sorted = true;



// Add event handler for notification of when ComboBox loses focus
this.comboBox.Leave += new EventHandler(comboBox_Leave);


}

// Property to provide access to ComboBox
public ComboBox ComboBox
{
get { return comboBox; }
}




// On edit, add scroll event handler, and display combo box
protected override void Edit(System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
{
Debug.WriteLine(String.Format("Edit {0}", rowNum));
base.Edit(source, rowNum, bounds, readOnly, instantText, cellIsVisible);
//

if (!readOnly && cellIsVisible)
{
// Save current row in the datagrid and currency manager associated with
// the data source for the datagrid
this.iCurrentRow = rowNum;
this.cm = source;

// Add event handler for datagrid scroll notification
this.DataGridTableStyle.DataGrid.Scroll += new EventHandler(DataGrid_Scroll);

// Site the combo box control within the bounds of the current cell
this.comboBox.Parent = this.TextBox.Parent;
Rectangle rect = this.DataGridTableStyle.DataGrid.GetCurrentCellBounds();
this.comboBox.Location = rect.Location;
this.comboBox.Size = new Size(this.TextBox.Size.Width, this.comboBox.Size.Height);

// Set combo box selection to given text
this.comboBox.SelectedIndex = this.comboBox.FindStringExact(this.TextBox.Text);

// Make the ComboBox visible and place on top text box control
this.comboBox.Show();
this.comboBox.BringToFront();
this.comboBox.Focus();
//this.comboBox.SelectedIndex = 0;
}
}

// Given a row, get the value member associated with a row. Use the value
// member to find the associated display member by iterating over bound datasource
protected override object GetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, int rowNum)
{
Debug.WriteLine(String.Format("GetColumnValueAtRow {0}", rowNum));
// // Given a row number in the datagrid, get the display member
object obj = base.GetColumnValueAtRow(source, rowNum);

// // Iterate through the datasource bound to the ColumnComboBox
// // Don't confuse this datasource with the datasource of the associated datagrid
CurrencyManager cm = (CurrencyManager)
(this.DataGridTableStyle.DataGrid.BindingContext[this.comboBox.DataSource]);
// Assumes the associated DataGrid is bound to a DataView, or DataTable that
// implements a default DataView
DataView dataview = ((DataView)cm.List);

int i;
for (i = 0; i < dataview.Count; i++)
{
if (obj.Equals(dataview[i][this.comboBox.ValueMember]))
break;
}

if (i < dataview.Count)
return dataview[i][this.comboBox.DisplayMember];

return DBNull.Value;
}

// Given a row and a display member, iterating over bound datasource to find
// the associated value member. Set this value member.
protected override void SetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, int rowNum, object value)
{
Debug.WriteLine(String.Format("SetColumnValueAtRow {0} {1}", rowNum, value));
object s = value;

// Iterate through the datasource bound to the ColumnComboBox
// Don't confuse this datasource with the datasource of the associated datagrid
CurrencyManager cm = (CurrencyManager)
(this.DataGridTableStyle.DataGrid.BindingContext[this.comboBox.DataSource]);
// Assumes the associated DataGrid is bound to a DataView, or DataTable that
// implements a default DataView
DataView dataview = ((DataView)cm.List);
int i;

for (i = 0; i < dataview.Count; i++)
{
if (s.Equals(dataview[i][this.comboBox.DisplayMember]))
break;
}

// If set item was found return corresponding value, otherwise return DbNull.Value
if(i < dataview.Count)
s = dataview[i][this.comboBox.ValueMember];
else
s = DBNull.Value;

base.SetColumnValueAtRow(source, rowNum, s);
}

// On datagrid scroll, hide the combobox
private void DataGrid_Scroll(object sender, EventArgs e)
{
Debug.WriteLine("Scroll");
this.comboBox.Hide();
}



// On combo box losing focus, set the column value, hide the combo box,
// and unregister scroll event handler
private void comboBox_Leave(object sender, EventArgs e)
{

try
{

DataRowView rowView = (DataRowView) this.comboBox.SelectedItem;
string s = (string) rowView.Row[this.comboBox.DisplayMember];
Debug.WriteLine(String.Format("Leave: {0} {1}", this.comboBox.Text, s));

SetColumnValueAtRow(this.cm, this.iCurrentRow, s);
Invalidate();

this.comboBox.Hide();
//MessageBox.Show(s);
this.DataGridTableStyle.DataGrid.Scroll -= new EventHandler(DataGrid_Scroll);


}
catch
{
}

}










}
}
Generaldatepicker set unchecked Pin
xrado9-Apr-05 1:07
xrado9-Apr-05 1:07 
GeneralRe: datepicker set unchecked Pin
Dave Kreskowiak9-Apr-05 5:48
mveDave Kreskowiak9-Apr-05 5:48 
GeneralRe: datepicker set unchecked Pin
xrado10-Apr-05 0:07
xrado10-Apr-05 0:07 
GeneralRe: datepicker set unchecked Pin
Luis Alonso Ramos11-Apr-05 13:23
Luis Alonso Ramos11-Apr-05 13:23 
GeneralRe: datepicker set unchecked Pin
xrado12-Apr-05 2:21
xrado12-Apr-05 2:21 
GeneralRe: datepicker set unchecked Pin
Luis Alonso Ramos12-Apr-05 5:30
Luis Alonso Ramos12-Apr-05 5:30 
QuestionHow can I make a collection of multidimensional arrays? Pin
Member 17592949-Apr-05 1:00
Member 17592949-Apr-05 1:00 
AnswerRe: How can I make a collection of multidimensional arrays? Pin
S. Senthil Kumar9-Apr-05 3:04
S. Senthil Kumar9-Apr-05 3:04 
GeneralRe: How can I make a collection of multidimensional arrays? Pin
9-Apr-05 4:14
suss9-Apr-05 4:14 
Question.NET 2.0 WebBrowser Control??? Pin
Anonymous8-Apr-05 23:35
Anonymous8-Apr-05 23:35 
QuestionHow to view AutoCad file In C# Pin
Newbie_Toy8-Apr-05 23:16
Newbie_Toy8-Apr-05 23:16 
AnswerRe: How to view AutoCad file In C# Pin
Dave Kreskowiak9-Apr-05 5:41
mveDave Kreskowiak9-Apr-05 5:41 
GeneralError in OleDBConnection : Object reference not set to an instance of an object Pin
sksandz8-Apr-05 21:23
sksandz8-Apr-05 21:23 
GeneralRe: Error in OleDBConnection : Object reference not set to an instance of an object Pin
big_trev8-Apr-05 21:58
big_trev8-Apr-05 21:58 
GeneralRe: Error in OleDBConnection : Object reference not set to an instance of an object Pin
sksandz8-Apr-05 22:04
sksandz8-Apr-05 22:04 
GeneralRe: Error in OleDBConnection : Object reference not set to an instance of an object Pin
big_trev8-Apr-05 22:15
big_trev8-Apr-05 22:15 
GeneralRe: Error in OleDBConnection : Object reference not set to an instance of an object Pin
Anonymous10-Apr-05 18:36
Anonymous10-Apr-05 18:36 

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.