|
.Net DataGrid combobox Simple Sample
|
|
VB.NET
' Set datagrid column styles
' Define comboCountry variable as a ComboBoxColumn column style object of DataGridComboBoxColumn class
Private WithEvents comboCountry As DataGridComboBoxColumn
' Define comboCapital variable as a ComboBoxColumn column style object of DataGridComboBoxColumn class
Private WithEvents comboCapital As DataGridComboBoxColumn
...........
' Set column styles
With .GridColumnStyles
' Set datagrid ComboBox Column Style for Country field
comboCountry = New DataGridComboBoxColumn(Dictionary, 0, 0, , , False)
.Add (comboCountry)
With .Item(0)
.MappingName = "Country"
.HeaderText = "Country"
.Width = 165
.NullText = String.Empty
End With
' Set datagrid ComboBox Column Style for Capital field
comboCapital = New DataGridComboBoxColumn(Dictionary, 1, 1, , , False)
.Add (comboCapital)
With .Item(1)
.MappingName = "Capital"
.HeaderText = "Capital"
.Width = 165
.NullText = String.Empty
End With
End With
...........
' "Country" datagrid cell has been left. Update corresponding "Capital" cell value in the current datagrid row
Private Sub comboCountry_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles comboCountry.Leave
Dim Capital As DataRow() = Dictionary.Select("Country='" + comboCountry.combo.Text + "'")
DataGrid1.Item(DataGrid1.CurrentRowIndex, 1) = Capital(0)(1)
End Sub
' "Capital" datagrid cell has been left. Update corresponding "Country" cell value in the current datagrid row
Private Sub comboCapital_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles comboCapital.Leave
Dim Country As DataRow() = Dictionary.Select("Capital='" + comboCapital.combo.Text + "'")
DataGrid1.Item(DataGrid1.CurrentRowIndex, 0) = Country(0)(0)
End Sub
|
C#
// Set column styles
// Define comboCountry variable as a ComboBoxColumn column style object of DataGridComboBoxColumn class
internal DataGridComboBoxColumn comboCountry;
// Define comboCapital variable as a ComboBoxColumn column style object of DataGridComboBoxColumn class
internal DataGridComboBoxColumn comboCapital;
...........
// Set column styles
// Set datagrid ComboBox ColumnStyle for Country field
comboCountry = (DataGridComboBoxColumn) new DataGridComboBoxColumn(ref Dictionary, 0, 0, true, false, false, DataGridComboBoxColumn.DisplayModes.ShowDisplayMember, 0);
comboCountry.Leave += new DataGridComboBoxColumn.LeaveEventHandler(this.comboCountry_Leave);
TblStyle.GridColumnStyles.Add(comboCountry);
TblStyle.GridColumnStyles[0].MappingName = "Country";
TblStyle.GridColumnStyles[0].HeaderText = "Country";
TblStyle.GridColumnStyles[0].Width = 165;
TblStyle.GridColumnStyles[0].NullText = string.Empty;
// Set datagrid ComboBox ColumnStyle for Capital field
comboCapital = (DataGridComboBoxColumn) new DataGridComboBoxColumn(ref Dictionary, 1, 1, true, false, false, DataGridComboBoxColumn.DisplayModes.ShowDisplayMember, 0);
comboCapital.Leave += new DataGridComboBoxColumn.LeaveEventHandler(this.comboCapital_Leave);
TblStyle.GridColumnStyles.Add(comboCapital);
TblStyle.GridColumnStyles[1].MappingName = "Capital";
TblStyle.GridColumnStyles[1].HeaderText = "Capital";
TblStyle.GridColumnStyles[1].Width = 165;
TblStyle.GridColumnStyles[1].NullText = string.Empty;
...........
// "Country" datagrid cell has been left. Update corresponding "Capital" cell value in the current datagrid row
private void comboCountry_Leave(object sender, System.EventArgs e)
{
System.Data.DataRow[] Capital = Dictionary.Select("Country='" + comboCountry.combo.Text + "'");
DataGrid1[DataGrid1.CurrentRowIndex, 1] = Capital[0][1];
}
// "Capital" datagrid cell has been left. Update corresponding "Country" cell value in the current datagrid row
private void comboCapital_Leave(object sender, System.EventArgs e)
{
System.Data.DataRow[] Country = Dictionary.Select("Capital='" + comboCapital.combo.Text + "'");
DataGrid1[DataGrid1.CurrentRowIndex, 0] = Country[0][0];
}
|
|
|
|
|
|
environment and programming model for constructing a range of software solutions. RustemSoft develops the assemblies (dll) for .NET developers. With the RustemSoft .NET assemblies and controls, customers gained the benefits of enhanced tool and framework functionality for building enterprise-critical software.
RustemSoft’s .NET programming components are reducing the amount of code required to accomplish common tasks and delivering high-end features for advanced .NET developers.
RustemSoft presents DataGridColumns .NET assembly for VB.NET, C#, C++, J# the intelligent software package designed for .NET developers.
A quantity of jobs you may want to achieve with the Windows Forms DataGrid control are, unexpectedly, more troublesome than you might expect. Principally, this is because the Windows Forms DataGrid control is column-based, rather than cell-based. As a result, to attain most tasks, you have to work with the columns, not the cells themselves.
DataGridColumns .NET assembly from RustemSoft is a DataGrid Columns Styles software package specifically designed for .NET developers. The assembly allows you to use all strengths of the MS Windows .NET forms DataGrid control without waiving the user interface elements your customers need.
|
|
|