0

search gridview 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(); }       
    }
Almir Vuk
  • 2,983
  • 1
  • 18
  • 22
  • It is entirely unclear what your question is about. Convert what and for what purpose? What text? Consider expanding your explanation of the problem. – Andrew Sklyarevsky Jul 25 '16 at 07:18
  • for search. ill put image.. well as u can isee iam using locateby value thats mean i need to type precise text Ballet because of case sensitive. and the thing is , i dont to type it Ballet to search but just type Bal. and the gridview select the ballet record –  Jul 25 '16 at 07:37
  • Try to iterate all records in datagridview and select just record whitch column genre starts with your text input. For example in foreach cycle put if(yourDataGridViewRow.Cell["genre"].Value.ToString().StartsWith(textInput)) – Jiří Vrbas Jul 25 '16 at 08:20
  • @JiříVrbas thank for reply , iam using devexpress, cant use datagridview.. only got gridview1 and gridcontrol1. can u type in full code ? :p –  Jul 25 '16 at 08:29

2 Answers2

0
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.

Jiří Vrbas
  • 155
  • 7
  • it reads all loop without stop. so it loop from start to end cant read the string in textbox –  Jul 25 '16 at 09:21
  • you mean that textBox6.text is empty like ""? so if statement never be true? – Jiří Vrbas Jul 25 '16 at 09:24
  • i try modify it like this `for (int i = 0; i < gridView1.RowCount; i++) { var rosw = gridView1.GetDataRow(i); var genre = rosw["genre"].ToString(); if (genre.Contains(textBox8.Text)) { MessageBox.Show(genre); gridView1.FocusedRowHandle = i; } }` but i still need to type it in exact string ;( –  Jul 25 '16 at 10:01
  • what you mean in exact string? You must write Ballet like in your example to go in if statement and when you write just Ball it dont go in if statement? – Jiří Vrbas Jul 25 '16 at 12:34
  • Use debuger to see values in genre and textBox6.Text – Jiří Vrbas Jul 25 '16 at 12:35
  • yep, but iam already post my own answer maybe it can use like that –  Jul 26 '16 at 03:01
0

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;
            }
        }