Is there a way to convert it, from exact value text become consist of? So I don't need to type Ballet instead of Bal.
Here's the code:
private void button6_Click_1(object sender, EventArgs e)
{
ColumnView View = gridControl1.MainView as ColumnView;
View.BeginUpdate();
try
{
int rowHandle = 0;
DevExpress.XtraGrid.Columns.GridColumn col = View.Columns["genre"];
while (true)
{
// // Locate the next row
rowHandle = View.LocateByValue(rowHandle, col, textBox6.Text);
// // Exit the loop if no row is found
if (rowHandle == DevExpress.XtraGrid.GridControl.InvalidRowHandle)
break;
//// Perform specific operations on the found row
gridView1.FocusedRowHandle = rowHandle;
rowHandle++;
}
}
finally { View.EndUpdate(); }
}
for (int i = 0; i < gridView1.VisibleRowCount; i++)
{
var row = gridView1.GetDataRow(i);
var genre = row["ColumnName"].ToString(); //ColumnName is your genre Column name
if(genre.StartsWith(textBox6.text)){
//here you can set row sellected
}
}
I dont have experience with devexpress but you can try it like this.
i dont if this what u seek, but it solved my own problem
for (int i = 0; i < gridView1.RowCount; i++)
{
var rosw = gridView1.GetDataRow(i);
var genre = rosw["genre"].ToString();
int tmpg = 0;
// //tmpg = genre.IndexOf(textBox8.Text, StringComparison.OrdinalIgnoreCase);
if (genre.IndexOf(textBox8.Text, StringComparison.OrdinalIgnoreCase) >= 0)
{
//if (tmpg >= 1)
// MessageBox.Show(genre);
gridView1.FocusedRowHandle = i;
break;
}
}
Related
I have DataGridView which consist of these data
From these data i would like to make the first column, airport name to group the third column and sum to their corresponding ActLoadQuantityTo which is in the fifth column, the cargo type which landed on the airport. right now my chart is messed up as it look like this
for (int j = 0; j < dgv_3.Rows.Count; j++)
{
double Load_qty = 0;
double new_load_qty = 0;
DiscPort = dgv_3.Rows[j].Cells["ActDiscDischargingPort"].Value.ToString();
DestType = dgv_3.Rows[j].Cells["SchLoadDestination"].Value.ToString();
CargoType = dgv_3.Rows[j].Cells["SchLoadCargoType"].Value.ToString();
string CargoType2 = "Series-" + CargoType;
Load_qty = Convert.ToDouble(dgv_3.Rows[j].Cells["ActLoadQuantityTon"].Value);
if (chart3.Series.IndexOf(DiscPort) != -1)
{
chart3.Series["000 - Port"].Points.AddY(Load_qty);
}
else
{
chart3.Series["000 - Port"].Points.AddXY(DiscPort, Load_qty);
}
}
no grouping of series,etc. i've tried adding more series but it just doesn't make sense toward the DataGridView. and my expectation is that i would like the chart to look like this as I've described before
Any idea what set of code should it be?
I found my desired result by using this code
public void isichartdomestic(System.Data.DataTable initialDataSource)
{
chart3.Titles.Add("Your title");
chart3.Legends.Add("Your Legend");
for (int i = 1; i < initialDataSource.Columns.Count; i++)
{
System.Windows.Forms.DataVisualization.Charting.Series series = new System.Windows.Forms.DataVisualization.Charting.Series();
foreach (DataRow dr in initialDataSource.Rows)
{
double y = (double)dr[i];
series.Points.AddXY(dr["DiscPort"].ToString(), y);
TotalDomestic += y;
}
chart3.Series.Add(series);
string NamaSeries = series.ToString();
NamaSeries = NamaSeries.Replace("Series-","");
chart3.Series[NamaSeries].IsValueShownAsLabel = true;
chart3.Series[NamaSeries].IsVisibleInLegend = true;
if (NamaSeries == "Series1")
{
chart3.Series[NamaSeries].LegendText = "Bag";
}
else if (NamaSeries == "Series2")
{
chart3.Series[NamaSeries].LegendText = "Bulk";
}
else if (NamaSeries == "Series3")
{
chart3.Series[NamaSeries].LegendText = "Clinker";
}
else if (NamaSeries == "Series4")
{
chart3.Series[NamaSeries].LegendText = "Container";
}
}
lb_TotalDomestic.Text = Convert.ToString("Total Domestic: " + TotalDomestic);
TotalDomesticExport += TotalDomestic;
}
I wanted to do select/ deselect with one checkbox. I have tried to get the index of the selected item. I haven't been able to get this, so I tried to change the name of the box. Still no success.
foreach (var item in DATAsetname_INIlist)
{
checkedListBox2.Items.Add(item);
}
if (checkedListBox2.Items.Count != 0)
{
checkedListBox2.Items.Add("Select all");
}
private void checkedListBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (checkedListBox2.Items.Count != 0)
{
if (checkedListBox2.SelectedItem.ToString() == "Select all")
{
for (int i = 0; i < checkedListBox2.Items.Count; i++)
{
checkedListBox2.SetItemChecked(i, true);
}
string changed = "Deselect all";
checkedListBox2.SelectedItem =changed;
}
if (checkedListBox2.SelectedItem.ToString() == "Deselect all")
{
for (int i = 0; i < checkedListBox2.Items.Count; i++)
{
checkedListBox2.SetItemChecked(i, false);
}
string changed = "Select all";
checkedListBox2.SelectedItem = changed;
}
}
}
can you please help on this ? thank you
Have done quick exercise. Please modify your code accordingly.
/// <summary>
/// Check all check boxes and vice versa
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ChkSelectAll_CheckedChanged(object sender, EventArgs e)
{
//Declare your checkedListBox2 count
iCount = checkedListBox2.Items.Count;
if (sender != null)
{
for (int i = 1; i <= iCount; i++)
{
CheckBox ck = null;
Control[] chkTest = this.Controls.Find("chkDrive" + i, true);
if (chkTest.Length > 0)
{
if (chkSelectAll.Checked)
{
for (int j = 0; j < chkTest.Length; j++)
{
ck = (CheckBox)chkTest[j];
ck.Checked = true;
}
}
else
{
for (int j = 0; j < chkTest.Length; j++)
{
ck = (CheckBox)chkTest[j];
ck.Checked = false;
}
}
}
}
}
}
can you try this.
try
{
checkedListBox1.SelectedIndexChanged -= checkedListBox1_SelectedIndexChanged;
if (checkedListBox1.Items.Count != 0)
{
if (checkedListBox1.SelectedItem.ToString() == "Select all")
{
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
checkedListBox1.SetItemChecked(i, true);
}
string changed = "Deselect all";
checkedListBox1.Items[checkedListBox1.SelectedIndex] = changed;
}
else if (checkedListBox1.SelectedItem.ToString() == "Deselect all")
{
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
checkedListBox1.SetItemChecked(i, false);
}
string changed = "Select all";
checkedListBox1.Items[checkedListBox1.SelectedIndex] = changed;
}
}
}
catch (Exception ex)
{
}
finally
{
checkedListBox1.SelectedIndexChanged += checkedListBox1_SelectedIndexChanged;
}
If this is C# based, windows application.
Search form collection and find all check box on form, using for each.
Code
foreach(CheckBox item in Form.Control)
{
Item.Checked=true;
}
For check list box
for(int i;I<checklistbox.items.count;I++)
{
checklistbox.SetItemChecked(I,true);
}
When i work with c# i had litle simillar problem in my case was enought was to replace if(string==string) by string.equals(string)
Btw few questions:
checkedListBox2.SelectedItem.ToString() what is value in here where comparing?
Does your listener work at all?
Not better way to check which checkBox is taken comparing sender in switch?
How u declare checkedListBox2
By checkedListBox2.Items.Add(item); i suspect u create checkBoxes by hand can u show it? meybe something is there wrong
This part added after Lian comment
foreach(var item in DATAsetname_INIlist)
{
checkedListBox2.Items.Add(item);
}
if (checkedListBox2.Items.Count != 0) {
checkedListBox2.Items.Add("Select all");
}
private void checkedListBox2_SelectedIndexChanged (object sender, EventArgs e)
{
if (checkedListBox2.Items.Count != 0 && checkedListBox2.SelectedItem.ToString().equals("Select all")) {
changeStateOfSelectedItem("Deselect all", true);
} else if (checkedListBox2.SelectedItem.ToString().equals("Deselect all")) {
changeStateOfSelectedItem("Select all", false);
}
}
private void changeStateOfSelectedItem (String state, bolean stateToReplace){
for (int i = 0; i < checkedListBox2.Items.Count; i++) {
checkedListBox2.SetItemChecked(i, stateToReplace);
}
string changed = state;
checkedListBox2.SelectedItem = changed;
Here is my current code:
private void searchBtn_Click(object sender, EventArgs e)
{
//get the search term from the textbox
String searchTerm = textBox.Text;
//if the column index is 1 the we search by code and 2 if we search by name
int columnIndex = 0;
if (codeRadioBtn.Checked)
columnIndex = 1;
else
columnIndex = 2;
gridView.ClearSelection();
int firstIndex = 0;
bool found = false;
for (int i = 0; i < gridView.Rows.Count; i++)
{
//change background color to DarkOrange for the rows that contain the searched value
if (gridView.Rows[i].Cells[columnIndex].Value.ToString().Contains(searchTerm, StringComparison.OrdinalIgnoreCase))
{
//gridView.Rows[i].Selected = true;
gridView.Rows[i].DefaultCellStyle.BackColor = Color.DarkOrange;
found = true;
if (firstIndex < 1)
{
firstIndex = i;
}
}
}
//display message if no item was found
if (!found)
MessageBox.Show("The search term was not found", "Warning");
else
// scroll grid to first highlighted row
this.gridView.Rows[firstIndex].Cells[0].Selected = true;
this.gridView.CurrentCell = this.gridView.Rows[firstIndex].Cells[0];
this.gridView.FirstDisplayedCell = this.gridView.CurrentCell;
}
I am trying to make it, onClick of the search button a second time it will set the current selected to the next highlighted row.
I have been trying for a while and can't figure it out. Any help would be greatly appreciated.
Use a List or Array to store all matches.
List<int> matchList = new List<int>();
e.g.
Whilst you are highlighting the rows, why not also add that row into a list.
gridView.Rows[i].DefaultCellStyle.BackColor = Color.DarkOrange;
matchList.add(i);
To work out whether it is the first click i.e. to load and highlight matches set a int outside of the button click to keep track of how many times you clicked the button.
int clickcount= 0;
Then after you have found and highlighted set clickcount to 1 and make sure you don't highlight again using an if statement, but instead run the below loop.
if (clickcount != 0 && clickcount !=matchList.Count-1)
{
this.gridView.CurrentCell = this.gridView.Rows[clickcount].Cells[0];
clickcount++;
}
else
{
clickcount = 0;
}
Full Example
int clickcount = 0;
List<int> matchList = new List<int>();
protected void searchBtn_Click(object sender, EventArgs e)
{
if (clickcount == 0)
{
//get the search term from the textbox
String searchTerm = textBox.Text;
//if the column index is 1 the we search by code and 2 if we search by name
int columnIndex = 0;
if (codeRadioBtn.Checked)
columnIndex = 1;
else
columnIndex = 2;
gridView.ClearSelection();
int firstIndex = 0;
bool found = false;
for (int i = 0; i < gridView.Rows.Count; i++)
{
//change background color to DarkOrange for the rows that contain the searched value
if (gridView.Rows[i].Cells[columnIndex].Value.ToString().Contains(searchTerm, StringComparison.OrdinalIgnoreCase))
{
//gridView.Rows[i].Selected = true;
this.gridView.CurrentCell = gridView.Rows[0].Cells[0];
gridView.Rows[i].DefaultCellStyle.BackColor = Color.DarkOrange;
matchList.Add(i);
found = true;
if (firstIndex < 1)
{
firstIndex = i;
}
}
}
//display message if no item was found
if (!found)
{
MessageBox.Show("The search term was not found", "Warning");
}
//add one to the count to stop the search happing again.
clickcount = 1;
}
else
{
//if clickcount = 1+ or your've reached the end of your match list count
if (clickcount != 0 && clickcount != matchList.Count - 1)
{
//gridView.Rows[clickcount].DefaultCellStyle.BackColor = Color.Red;
this.gridView.CurrentCell = gridView.Rows[matchList[clickcount]].Cells[0];
clickcount++;
}
else
{
MessageBox.Show("No More Found");
clickcount = 0;
matchList.Clear();
}
}
}
Hi I want to add my checkedboxList checked values inside grid view(Asp.net), below existing rows how can I do this. This is the code how I tried but that is not correctly adding
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
// check view state is not null
if (ViewState["MailTracking"] != null)
{
//get datatable from view state
dt = (DataTable)ViewState["MailTracking"];
DataRow oItem = null;
if (dt.Rows.Count > 0)
{
for (int i = 1; i <= dt.Rows.Count; i++)
{
oItem = dt.NewRow();
string strValue = "";
for (int k = 0; k < CheckBoxListBranch.Items.Count; k++)
{
if (CheckBoxListBranch.Items[k].Selected)
{
strValue = CheckBoxListBranch.Items[k].Value;
oItem[0] = CheckBoxListBranch.Items[k].Text;
}
}
}
//Remove initial blank row
if (dt.Rows[0][0].ToString() == "")
{
dt.Rows[0].Delete();
dt.AcceptChanges();
}
dt.Rows.Add(oItem);
ViewState["MailTracking"] = dt;
GVDisplay.DataSource = dt;
GVDisplay.DataBind();
}
}
}
My asp:CheckBoxList ID is: CheckBoxListBranch I used onselectedindexchanged="CheckBoxList1_SelectedIndexChanged" inside asp:CheckBoxList.
I think you meant the below code statement
oItem[0] = CheckBoxListBranch.Items[k].Text;
to actually be, notice that it's oItem[k] else every time you are adding/re-ading the element to the first column of the row
oItem[k] = CheckBoxListBranch.Items[k].Text;
Per your comment: in that case you should move the code line dt.Rows.Add(oItem); inside your for loop as below
for (int k = 0; k < CheckBoxListBranch.Items.Count; k++)
{
if (CheckBoxListBranch.Items[k].Selected)
{
strValue = CheckBoxListBranch.Items[k].Value;
oItem[0] = CheckBoxListBranch.Items[k].Text;
dt.Rows.Add(oItem);
}
}
Hi i am new to programming in c# wpf i just need to create a datagrid of some details i made it and the one major task is the while adding the serial number will be incremented as 1,2,3,4,etc.as when i remove an record from the datagrid the serial number to rearrange according to it eg:sno:1,2,3,4,5,6.
after removing the 3rd row it should be 1,2,3,4,5 instaed of 1,2,4,5,6.
similarly for inserting a row between 1,2,3 after adding it should be 1,2,3,4 task is row nust be added between 2 and 3 the new row help need
void mbtninsertstep_Click(object sender, RoutedEventArgs e) {
int rowindex = mdatagridedit.Items.IndexOf(mdatagridedit.CurrentCell);
if (rowindex >= 0) {
int rowcount = programtable.Rows.Count;
msteps.Add(new Steps { mStepno = count, mPosition = "0",
mRepeat = "NONE", mCount = "1", mAftercut = "NONE" });
int p = rowindex + 1;
for (int i = 0; i < rowcount + 1; i++) {
programtable.Rows[i][0] = p++;
} edited = true;
}
}
delete button code
insert button code.
void mbtndeletestep_Click(object sender, RoutedEventArgs e)
{
int deleterow;
DataGridView dg = new DataGridView();
// msteps.Remove((Steps)mdatagridedit.SelectedItem);
int rowindex = dg.CurrentRow.Index;
if (rowindex >= 0) {
int rowcount = programtable.Rows.Count;
int temp = dg.CurrentCell.RowIndex;
programtable.Rows.RemoveAt(temp);
int p = temp + 1;
for (int i = rowindex; i < rowcount - 1; i++) {
programtable.Rows[i][0] = p++;
}
int RowCountAfterDeleting = programtable.Rows.Count;
}
//int p = mdatagridedit.Items.Count;
// if (mdatagridedit.SelectedItem == null) {
// System.Windows.Forms.MessageBox.Show("Select an row");
// } else {
//msteps.RemoveAt(mdatagridedit.SelectedIndex);
//int p = mdatagridedit.SelectedIndex + 1;
// for(int i = mdatagridedit.SelectedIndex;
i < mdatagridedit.Items.Count - 1; i++){
// Steps step = new Steps();
// step.mStepno = p - 1;
// } int p1 = programtable.Rows.Count;
//}
}