I have a DevExpress GridControl in my current WinForms application. I need to display a hyperlink control (RepositoryItemHyperLinkEdit) in a column. I have added the RepositoryItemHyperLinkEdit via designer, but when I am running the application, hyperlink is not displaying.
Like to display buttons we are using:
repositoryItemButtonEdit1.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
repositoryItemButtonEdit1.Buttons[0].Caption = "Get Sql Query";
So please tell me what I will write to display hyperlink in a column.
You can use the following code to display hyperlink in grid column:
GridColumn hyperLinkColumn = gridView1.Columns["Hyperlink"];
//...
RepositoryItemHyperLinkEdit hyperLinkEdit = new RepositoryItemHyperLinkEdit();
hyperLinkColumn.ColumnEdit = hyperLinkEdit; // this line associated hyperlink with column
hyperLinkEdit.OpenLink += hyperLinkEdit_OpenLink;
//...
void hyperLinkEdit_OpenLink(object sender, OpenLinkEventArgs e) {
MessageBox.Show("HyperLinkEdit clicked!");
}
If you want to display aditional button in the same column you can use the following approach:
hyperLinkEdit.Buttons[0].Kind = ButtonPredefines.Glyph;
hyperLinkEdit.Buttons[0].Caption = "Get SQL Query";
hyperLinkEdit.ButtonClick += hyperLinkEdit_ButtonClick;
hyperLinkColumn.ShowButtonMode = ShowButtonModeEnum.ShowAlways; // always display button in this column
//...
void hyperLinkEdit_ButtonClick(object sender, ButtonPressedEventArgs e) {
MessageBox.Show("HyperLinkEdit's button clicked!");
}
You didn't mentioned that you've set up the ColumnEdit property of the column to the repository item. If you haven't:
Note that you may have to use the gridView_MouseUp event in order to catch the click event without waiting that the grid give the focus to the cell.
gridColumn.ColumnEdit = new RepositoryItemHyperLinkEdit();
gridColumn.OptionsColumn.ReadOnly = true;
gridColumn.OptionsColumn.AllowEdit = false;
gridView.MouseUp += gridView_MouseUp;
private void gridViewDesk_MouseUp(object sender, MouseEventArgs e)
{
GridView gridView = (GridView) sender;
if (e.Button == MouseButtons.Left && e.Clicks == 1)
{
GridHitInfo hitInfo = gridView.CalcHitInfo(e.Location);
if (hitInfo.InRowCell && hitInfo.Column == this.gridColumn)
{
MessageBox.Show("Click " + hitInfo.RowHandle);
}
}
}
Related
I want to have a data gridview that is bounded to SQL data source that has a column with name status also I need this column to be combobox, to be better to the user to select the value instead of writing it, is it possible ?
I've searched and I've found this Adding bound combobox to datagridview and it answered how to add comobobox to bounded datagridview, but this is not what I need
I've also tried to make another solution in a different way by using menustrip and it works fine but I can't edit the cell value after the user select menusttrip item as the datagridview is bounded to data source
Here is a part of my code related to the 2nd solution:
dtSamples = cMaster.Select_Samples(nKeyNo, DateTime.Today, strMachine);
dataGridView_Samples.DataSource = dtSamples;
//here is the event that shows the menustrip when the user clicked on the desired column
private void dataGridView_Samples_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
DataGridView.HitTestInfo hit = dataGridView_Samples.HitTest(e.X, e.Y); //Get the clicked cell
if (e.RowIndex < nNewRowIndex) //If it's a header, ignore
return;
dataGridView_Samples.CurrentCell = dataGridView_Samples[e.ColumnIndex, e.RowIndex]; //Select the cell for future info
StatusRowIndex = e.RowIndex;
if (dataGridView_Samples.CurrentCell.ColumnIndex == 4) //If this is the priority column
{
contextMenuStrip_Status.Show(Cursor.Position.X, Cursor.Position.Y); //Show the strip
}
}
}
//here is the event of selecting item of menustrip and it doesn't show the value in the cell
private void toolStripMenuItem_Repair_Click(object sender, EventArgs e)
{
if (nNewRowIndex == -1)
{
dataGridView_Samples.CurrentCell.Value = "Repair";
dataGridView_Samples.Rows[StatusRowIndex].Cells[4].Value = 4;
dataGridView_Samples.NotifyCurrentCellDirty(true);
}
else
{
dataGridView_Samples.Rows[nNewRowIndex].Cells[4].Value = "Repair";
// dataGridView_Samples.Rows[nNewRowIndex].Cells[4].Value = 4;
dataGridView_Samples.NotifyCurrentCellDirty(true);
dataGridView_Samples.BeginEdit(true);
dataGridView_Samples.EndEdit();
}
}
I have grid view, and I have already disable the column auto width so I can manually set the size of column. after manually resize there's a extra blank column. and what I want is :
To disable the select row function when i click on outside of the column in Active, code and generate
Remove the extra column.
I already success fully hide the remaining column with this event or code
private void gridView1_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
{
if (e.Column == null)
{
e.Handled = true;
}
}
The thing is I still can click on the outside of the genre, and the row selection still follow where I click
Handle the GridView.MouseDown event in the following way:
private void gridView1_MouseDown(object sender, MouseEventArgs e) {
GridView view = (GridView)sender;
var hi = view.CalcHitInfo(e.Location);
Console.WriteLine(hi.HitTest);
if (hi.InRow && !hi.InRowCell)
DXMouseEventArgs.GetMouseArgs(e).Handled = true;
}
I want to get the first element of telerik multi combo box which is a column of a telerik grid view
when user selects a row i want to get the first element of that row and pass it to my DB
i've done some thing but i geuss it's not enough
if (Ref_MultiColumnComboBox.MultiColumnComboBoxElement.SelectedIndex >= 0)
{
var tr = Ref_MultiColumnComboBox.MultiColumnComboBoxElement
.EditorControl.Rows[Ref_MultiColumnComboBox.MultiColumnComboBoxElement.SelectedIndex]
.Cells["Id"].Value.ToString();
MessageBox.Show("m= {0}" + " // " + tr);
}
else
{
MessageBox.Show("", "Error");
}
the problem is that when user selects some row or doesn't selectedindex is allways -1
Here is one way to do it for RadMultiColumnComboBox control:
void radMultiColumnComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewDataRowInfo selectedRow = (GridViewDataRowInfo)radMultiColumnComboBox1.SelectedItem;
Console.WriteLine(selectedRow.Cells["Id"].Value.ToString());
}
The SelectedItem provides a reference to the selected row in the inner grid, from where you can access its cells and values.
If GridViewMultiComboBoxColumn is used, then you can use either the ValueChanged event, or the CellValueChangned events to get the row of the currently selected item:
void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
{
RadMultiColumnComboBoxElement mccbEditor = (RadMultiColumnComboBoxElement)e.ActiveEditor;
GridViewDataRowInfo selectedRow = (GridViewDataRowInfo)mccbEditor.SelectedItem;
Console.WriteLine(selectedRow.Cells["Id"].Value.ToString());
}
void radGridView1_ValueChanged(object sender, EventArgs e)
{
RadMultiColumnComboBoxElement mccbEditor = (RadMultiColumnComboBoxElement)radGridView1.ActiveEditor;
GridViewDataRowInfo selectedRow = (GridViewDataRowInfo)mccbEditor.SelectedItem;
Console.WriteLine(selectedRow.Cells["Id"].Value.ToString());
}
I have devexpress datagridview that have 10 columns with first column as Name which is non-editable but the user should be able to copy the cell content(Name).
private void gridViewBatches_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
{
GridView view = sender as GridView;
if (view.FocusedColumn.FieldName == "Batch No") //Editable true
{
e.Cancel = false;
} else //Other column editble false
{
e.Cancel = true;
}
}
One solution is to change ReadOnly or AllowEdit options of your columns.
Other solution is to use the ShowingEditor event of the view and disable cell editing via code using the event handler's e.Cancel parameter.
Here is the code snippet:
//Disable updating on the entire grid
uGrid1.DisplayLayout.Override.AllowUpdate = DefaultableBoolean.False;
// Disable the first column in the first band
ultraGrid1.DisplayLayout.Bands[0].Columns[0].CellActivation = Activation.Disabled;
// Disable the first cell in the grid
uGrid1.Rows[0].Cells[0].Activation = Activation.Disabled;
ultraGrid1.DisplayLayout.Bands[0].Columns[0].CellActivation = Activation.Disabled;
Update :
Following solution works for Amol as confirmed in comments, including here for others benefit.
private void gridViewBatches_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
{
GridView view = sender as GridView;
if (view.FocusedColumn.FieldName == "Batch No") //Editable true
{
e.Cancel = false;
} else //Other column editble false
{
e.Cancel = true;
}
}
So, when I click Select I want to show in a Label all datas that contain one row. I have managed to make this, except DropdownList. When I click "Select" it's just empty.
protected void GridView_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
Label1.Text = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
Label2.Text = GridView1.Rows[e.NewSelectedIndex].Cells[2].Text;
Label3.Text = GridView1.Rows[e.NewSelectedIndex].Cells[3].Text;
}
P.S.: I have not done this programmatically. The only code I've wrote on .aspx.cs file is the code above.
Use this to find the value. its not showing the value because of template field control.
I have used the gridview control that you pasted in pastebin.
protected void GridView_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) {
Label drpValue =
(Label)this.GridView1.Rows[e.NewSelectedIndex].Cells[1].FindControl("Label1");
Lbl1.Text = drpValue.Text;
Lbl2.Text = GridView1.Rows[e.NewSelectedIndex].Cells[2].Text;
Lbl3.Text = GridView1.Rows[e.NewSelectedIndex].Cells[3].Text;
}